Skip to content

BUG: indexing regression with datetime index #34860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
0x0L opened this issue Jun 18, 2020 · 4 comments · Fixed by #34917
Closed

BUG: indexing regression with datetime index #34860

0x0L opened this issue Jun 18, 2020 · 4 comments · Fixed by #34917
Labels
Datetime Datetime data dtype good first issue Indexing Related to indexing on series/frames, not to indexes themselves Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@0x0L
Copy link
Contributor

0x0L commented Jun 18, 2020

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

@0x0L 0x0L added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 18, 2020
@0x0L 0x0L changed the title BUG: indexing regression BUG: indexing regression with datetime index Jun 18, 2020
@TomAugspurger
Copy link
Contributor

Working as expected on master

Out[1]:
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]

I don't recall which commit fixed it, but it'd be good to ensure that we have test coverage for this in pandas/tests/series/indexing/test_datetime.py.

@TomAugspurger TomAugspurger added Needs Tests Unit test(s) needed to prevent regressions good first issue Indexing Related to indexing on series/frames, not to indexes themselves Datetime Datetime data dtype and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 18, 2020
@TomAugspurger TomAugspurger added this to the Contributions Welcome milestone Jun 18, 2020
@0x0L
Copy link
Contributor Author

0x0L commented Jun 18, 2020

@TomAugspurger
Thanks. I'll check to find the exact commit: it is fixed in master but not in 1.0.5
I'll add my example as a test case if you think that's a good idea

@faraz16iqbal
Copy link

Interested in working on this issue!

@0x0L
Copy link
Contributor Author

0x0L commented Jun 18, 2020

Hi @faraz16iqbal !
Feel free to submit a pull request. The contributing guide is a good starting point.

@jreback jreback modified the milestones: Contributions Welcome, 1.1 Jun 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype good first issue Indexing Related to indexing on series/frames, not to indexes themselves Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants