Skip to content
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

REGR: string indexing on PeriodIndex raises KeyError on master (not yet released) #33964

Closed
3 tasks done
simonjayhawkins opened this issue May 4, 2020 · 3 comments · Fixed by #34736
Closed
3 tasks done
Labels
Blocker Blocking issue or pull request for an upcoming release Bug Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@simonjayhawkins
Copy link
Member

simonjayhawkins commented May 4, 2020

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

>>> import pandas as pd
>>>
>>> pd.__version__
'1.1.0.dev0+1466.ga3477c769'
>>>
>>> index = pd.period_range(start="2000", periods=20, freq="B")
>>> series = pd.Series(range(20), index=index)
>>>
>>> series.index
PeriodIndex(['2000-01-03', '2000-01-04', '2000-01-05', '2000-01-06',
             '2000-01-07', '2000-01-10', '2000-01-11', '2000-01-12',
             '2000-01-13', '2000-01-14', '2000-01-17', '2000-01-18',
             '2000-01-19', '2000-01-20', '2000-01-21', '2000-01-24',
             '2000-01-25', '2000-01-26', '2000-01-27', '2000-01-28'],
            dtype='period[B]', freq='B')
>>>
>>> series.loc["2000-01-14"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\simon\pandas\pandas\core\indexing.py", line 871, in __getitem__
    return self._getitem_axis(maybe_callable, axis=axis)
  File "C:\Users\simon\pandas\pandas\core\indexing.py", line 1102, in _getitem_axis
    return self._get_label(key, axis=axis)
  File "C:\Users\simon\pandas\pandas\core\indexing.py", line 1051, in _get_label
    return self.obj.xs(label, axis=axis)
  File "C:\Users\simon\pandas\pandas\core\generic.py", line 3512, in xs
    loc = self.index.get_loc(key)
  File "C:\Users\simon\pandas\pandas\core\indexes\period.py", line 519, in get_loc
    raise KeyError(key)
KeyError: '2000-01-14'
>>>

Problem description

regression in #31172 (i.e. not yet released)

9a211aa is the first bad commit
commit 9a211aa
Author: jbrockmendel [email protected]
Date: Sat Jan 25 08:07:15 2020 -0800

BUG: inconsistency between PeriodIndex.get_value vs get_loc (#31172)

cc @jbrockmendel

Expected Output

>>> import pandas as pd
>>>
>>> pd.__version__
'1.0.3'
>>>
>>> index = pd.period_range(start="2000", periods=20, freq="B")
>>> series = pd.Series(range(20), index=index)
>>>
>>> series.index
PeriodIndex(['2000-01-03', '2000-01-04', '2000-01-05', '2000-01-06',
             '2000-01-07', '2000-01-10', '2000-01-11', '2000-01-12',
             '2000-01-13', '2000-01-14', '2000-01-17', '2000-01-18',
             '2000-01-19', '2000-01-20', '2000-01-21', '2000-01-24',
             '2000-01-25', '2000-01-26', '2000-01-27', '2000-01-28'],
            dtype='period[B]', freq='B')
>>>
>>> series.loc["2000-01-14"]
9
>>>

Output of pd.show_versions()

[paste the output of pd.show_versions() here leaving a blank line after the details tag]

@simonjayhawkins simonjayhawkins added Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version Period Period data type labels May 4, 2020
@simonjayhawkins simonjayhawkins added this to the 1.1 milestone May 4, 2020
@mroeschke mroeschke added the Bug label May 11, 2020
@simonjayhawkins simonjayhawkins added the Blocker Blocking issue or pull request for an upcoming release label May 19, 2020
@TomAugspurger
Copy link
Contributor

@jbrockmendel do you have time to look into this in the next week or two? If not I can take a look next week.

@jbrockmendel
Copy link
Member

I'm taking a break for a little while, can look at this when i get back

@TomAugspurger
Copy link
Contributor

No worries. Enjoy the break.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocker Blocking issue or pull request for an upcoming release Bug Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants