Skip to content

Cannot access label property when indexing a single level #434

@wtbarnes

Description

@wtbarnes

Accessing the label property of Levels when indexing a single level is broken.

import fiasco
import astropy.units as u

s_10 = fiasco.Ion('S X', 1*u.MK)
s_10[0].label
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[125], line 2
      1 s_10 = fiasco.Ion('S X', 1*u.MK)
----> 2 s_10[0].label

File [~/Documents/projects/active-region-evolution-study/.venv/lib/python3.12/site-packages/fiasco/levels.py:103](http://localhost:8888/lab/workspaces/auto-A/tree/Documents/projects/active-region-evolution-study/notebooks/~/Documents/projects/active-region-evolution-study/.venv/lib/python3.12/site-packages/fiasco/levels.py#line=102), in Levels.label(self)
     97 @property
     98 def label(self):
     99     """
    100     Label denoting level configuration, multiplicity, angular momentum label,
    101     and total angular momentum.
    102     """
--> 103     zipped = zip(self.configuration,
    104                  self.multiplicity,
    105                  self.orbital_angular_momentum_label,
    106                  self.total_angular_momentum)
    107     return np.array([f"{i} {j}{k}{Fraction(l.value)}" for i,j,k,l in zipped])

TypeError: iteration over a 0-d array

This, however, does work:

s_10[:1].label

This issue seems to be trying to zip together arrays with 0 length. It may be that we just need to special case instances where the properties have length 0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    IonAnything related to the Ion objectbug

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions