Skip to content

Inconsistent handling of .item with PeriodIndex #846

@max-sixty

Description

@max-sixty

Is this an inconsistency?

With DatetimeIndex, .item() gets the item, and .data gets a 0-d array:

In [14]: da=xr.DataArray(pd.DataFrame(pd.np.random.rand(10), index=pd.DatetimeIndex(start='2000', periods=10,freq='A')))

In [15]: p=da['dim_0'][0]

In [16]: p.values
Out[16]: numpy.datetime64('2000-12-31T00:00:00.000000000')

In [17]: p.item()
Out[17]: 978220800000000000L

But with a PeriodIndex, values gets the item, and so .item() fails

In [22]: da=xr.DataArray(pd.DataFrame(pd.np.random.rand(10), index=pd.PeriodIndex(start='2000', periods=10)))

In [23]: p=da['dim_0'][0]

In [24]: p.values
Out[24]: Period('2000', 'A-DEC')

In [25]: p.item()
AttributeError: 'pandas._period.Period' object has no attribute 'item'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions