Skip to content

BUG: indexing regression with datetime index #34860

Closed
@0x0L

Description

@0x0L

Sample code:

import pandas as pd

idx = pd.date_range('2008', '2009')
idx.to_series()['2008']

in 0.25.3 we get

2008-01-01   2008-01-01
2008-01-02   2008-01-02
2008-01-03   2008-01-03
2008-01-04   2008-01-04
2008-01-05   2008-01-05
                ...    
2008-12-27   2008-12-27
2008-12-28   2008-12-28
2008-12-29   2008-12-29
2008-12-30   2008-12-30
2008-12-31   2008-12-31
Freq: D, Length: 366, dtype: datetime64[ns]

in >= 1.0.0 (up to 1.0.4 at least) we get

2008   2008-01-01
2008   2008-01-02
2008   2008-01-03
2008   2008-01-04
2008   2008-01-05
          ...    
2008   2008-12-27
2008   2008-12-28
2008   2008-12-29
2008   2008-12-30
2008   2008-12-31
Length: 366, dtype: datetime64[ns]

The index has dtype obj

Variantations like

idx.to_series().astype(str)['2008']
idx.to_series().loc['2008']

look unaffected

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypeIndexingRelated to indexing on series/frames, not to indexes themselvesNeeds TestsUnit test(s) needed to prevent regressionsgood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions