Skip to content

Indexing by a list of Periods fails to return a series #7710

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
numpand opened this issue Jul 9, 2014 · 7 comments · Fixed by #14117
Closed

Indexing by a list of Periods fails to return a series #7710

numpand opened this issue Jul 9, 2014 · 7 comments · Fixed by #14117
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type Testing pandas testing functions or related to the test suite
Milestone

Comments

@numpand
Copy link

numpand commented Jul 9, 2014

In [1]: import pandas as pd

In [2]: pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.7.final.0
python-bits: 32
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 30 Stepping 5, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.14.0
nose: 1.3.3
Cython: 0.20.2
numpy: 1.8.1
scipy: 0.14.0
statsmodels: 0.5.0
IPython: 2.1.0
sphinx: 1.2.2
patsy: 0.2.1
scikits.timeseries: None
dateutil: 1.5
pytz: 2014.4
bottleneck: None
tables: 3.1.1
numexpr: 2.3.1
matplotlib: 1.3.1
openpyxl: 1.8.5
xlrd: 0.9.3
xlwt: 0.7.5
xlsxwriter: 0.5.5
lxml: 3.3.5
bs4: 4.3.1
html5lib: 0.999
bq: None
apiclient: None
rpy2: 2.3.9
sqlalchemy: 0.9.4
pymysql: None
psycopg2: 2.5.3 (dt dec pq3 ext)

In [3]: s = pd.TimeSeries(1, [pd.Period('2002-01-01',freq='D')])

In [4]: s[[0]]
Out[4]:
2002-01-01    1
Freq: D, dtype: int64

In [5]: s[[pd.Period('2002-01-01',freq='D')]]
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-0e636383b52c> in <module>()
----> 1 s[[pd.Period('2002-01-01',freq='D')]]

C:\Python27\lib\site-packages\pandas\core\series.pyc in __getitem__(self, key)
    517             key = _check_bool_indexer(self.index, key)
    518
--> 519         return self._get_with(key)
    520
    521     def _get_with(self, key):

C:\Python27\lib\site-packages\pandas\core\series.pyc in _get_with(self, key)
    555                     # handle the dup indexing case (GH 4246)
    556                     if isinstance(key, (list, tuple)):
--> 557                         return self.ix[key]
    558
    559                     return self.reindex(key)

C:\Python27\lib\site-packages\pandas\core\indexing.pyc in __getitem__(self, key)
     68             return self._getitem_tuple(key)
     69         else:
---> 70             return self._getitem_axis(key, axis=0)
     71
     72     def _get_label(self, label, axis=0):

C:\Python27\lib\site-packages\pandas\core\indexing.pyc in _getitem_axis(self, key, axis, validate_iterable)
    849                 raise ValueError('Cannot index with multidimensional key')
    850
--> 851             return self._getitem_iterable(key, axis=axis)
    852         else:
    853             if com.is_integer(key):

C:\Python27\lib\site-packages\pandas\core\indexing.pyc in _getitem_iterable(self, key, axis)
    905             # existing labels are unique and indexer is unique
    906             if labels.is_unique and keyarr_is_unique:
--> 907                 return _reindex(keyarr, level=level)
    908
    909             else:

C:\Python27\lib\site-packages\pandas\core\indexing.pyc in _reindex(keys, level)
    875                 if axis != 0:
    876                     raise AssertionError('axis must be 0')
--> 877                 return self.obj.reindex(keys, level=level)
    878
    879         if com._is_bool_indexer(key):

C:\Python27\lib\site-packages\pandas\core\series.pyc in reindex(self, index, **kwargs)
   2026     @Appender(generic._shared_docs['reindex'] % _shared_doc_kwargs)
   2027     def reindex(self, index=None, **kwargs):
-> 2028         return super(Series, self).reindex(index=index, **kwargs)
   2029
   2030     def reindex_axis(self, labels, axis=0, **kwargs):

C:\Python27\lib\site-packages\pandas\core\generic.pyc in reindex(self, *args, **kwargs)
   1608         # if indicated must have index names equal here as well as values
   1609         if all([self._get_axis(axis).identical(ax)
-> 1610                 for axis, ax in axes.items() if ax is not None]):
   1611             if copy:
   1612                 return self.copy()

C:\Python27\lib\site-packages\pandas\core\index.pyc in identical(self, other)
    849         also equal
    850         """
--> 851         return (self.equals(other) and
    852                 all((getattr(self, c, None) == getattr(other, c, None)
    853                      for c in self._comparables)) and

C:\Python27\lib\site-packages\pandas\tseries\period.pyc in equals(self, other)
    822             return True
    823
--> 824         return np.array_equal(self.asi8, other.asi8)
    825
    826     def tolist(self):

AttributeError: 'numpy.ndarray' object has no attribute 'asi8'

@jreback
Copy link
Contributor

jreback commented Jul 9, 2014

yep a bug, note that a single period (e.g. only a single []) works as well as the parital string indexers (e.g. '2002-01-01')

@jreback jreback added this to the 0.15.0 milestone Jul 9, 2014
@numpand
Copy link
Author

numpand commented Jul 9, 2014

Yes, I noticed that as well. I can work around by using get_loc() on the index + iloc (which does work for a list).

@jreback
Copy link
Contributor

jreback commented Sep 8, 2014

cc @sinhrks

this seems to work now, any idea where fixed?

@jreback jreback modified the milestones: 0.15.1, 0.15.0 Sep 19, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@max-sixty
Copy link
Contributor

FYI confirming this does work

@jreback
Copy link
Contributor

jreback commented May 19, 2016

yes this does seem to work, @sinhrks has been busy!

ok, want to put up a validation test?

@jreback jreback modified the milestones: 0.18.2, Next Major Release May 19, 2016
@jreback jreback added the Testing pandas testing functions or related to the test suite label May 19, 2016
@jreback
Copy link
Contributor

jreback commented May 19, 2016

prob start a new file in tests/indexing/test_periods.py (and can move appropriate tests from other places there).

@sinhrks
Copy link
Member

sinhrks commented May 19, 2016

Sorry I've missed the prev notice. @MaximilianR thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants