Skip to content

API/BUG: Indexing a DatetimeIndex by Period #8358

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
seth-p opened this issue Sep 22, 2014 · 5 comments
Closed

API/BUG: Indexing a DatetimeIndex by Period #8358

seth-p opened this issue Sep 22, 2014 · 5 comments
Labels
Bug Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type

Comments

@seth-p
Copy link
Contributor

seth-p commented Sep 22, 2014

Curiously one can index a DatetimeIndex by the string representation of a Period, but not by an actual Period object. Is this intentional?

Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 2.2.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from pandas import Series, date_range, Period

In [2]: s = Series(range(365), index=date_range('2001-01-01', periods=365))

In [3]: s[str(Period('2001-03', 'M'))]
Out[3]:
2001-03-01    59
2001-03-02    60
2001-03-03    61
2001-03-04    62
2001-03-05    63
2001-03-06    64
2001-03-07    65
2001-03-08    66
2001-03-09    67
2001-03-10    68
2001-03-11    69
2001-03-12    70
2001-03-13    71
2001-03-14    72
2001-03-15    73
2001-03-16    74
2001-03-17    75
2001-03-18    76
2001-03-19    77
2001-03-20    78
2001-03-21    79
2001-03-22    80
2001-03-23    81
2001-03-24    82
2001-03-25    83
2001-03-26    84
2001-03-27    85
2001-03-28    86
2001-03-29    87
2001-03-30    88
2001-03-31    89
Freq: D, dtype: int32

In [4]: s[Period('2001-03', 'M')]
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-4-64d0668f17a9> in <module>()
----> 1 s[Period('2001-03', 'M')]

C:\Python34\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
    482     def __getitem__(self, key):
    483         try:
--> 484             result = self.index.get_value(self, key)
    485
    486             if not np.isscalar(result):

C:\Python34\lib\site-packages\pandas\tseries\index.py in get_value(self, series, key)
   1256                 return self.get_value_maybe_box(series, key)
   1257             except (TypeError, ValueError, KeyError):
-> 1258                 raise KeyError(key)
   1259
   1260     def get_value_maybe_box(self, series, key):

KeyError: Period('2001-03', 'M')
@jreback
Copy link
Contributor

jreback commented Sep 22, 2014

dupe of #7710

@jreback jreback closed this as completed Sep 22, 2014
@seth-p seth-p changed the title API/BUG: Indexing a DatetimeIndex by Pperiod API/BUG: Indexing a DatetimeIndex by Period Sep 22, 2014
@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type Duplicate Report Duplicate issue or pull request labels Sep 22, 2014
@seth-p
Copy link
Contributor Author

seth-p commented Sep 22, 2014

Per #7710 (comment), "a single period (e.g. only a single []) works", but that's not what I'm seeing...

@seth-p
Copy link
Contributor Author

seth-p commented Sep 22, 2014

... to be clear, it's not working in 14.0.1. I haven't checked in master...

Sorry for the dupe...

@jreback
Copy link
Contributor

jreback commented Sep 22, 2014

Its the same issue. @seth-p no worries.....pull-requests welcome!

@seth-p
Copy link
Contributor Author

seth-p commented Sep 22, 2014

not my bailiwick, I'm afraid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type
Projects
None yet
Development

No branches or pull requests

2 participants