Skip to content

Commit 879f5e9

Browse files
max-sixtyjreback
authored andcommitted
BUG: .ix with PeriodIndex isn't treated as integers, #4125
1 parent 724e15f commit 879f5e9

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

pandas/core/index.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
import datetime
33
import warnings
44
import operator
5-
65
from functools import partial
7-
from pandas.compat import range, zip, lrange, lzip, u, reduce, filter, map
8-
from pandas import compat
9-
import numpy as np
10-
116
from sys import getsizeof
7+
8+
import numpy as np
129
import pandas.tslib as tslib
1310
import pandas.lib as lib
1411
import pandas.algos as _algos
1512
import pandas.index as _index
1613
from pandas.lib import Timestamp, Timedelta, is_datetime_array
14+
15+
from pandas.compat import range, zip, lrange, lzip, u, map
16+
from pandas import compat
1717
from pandas.core.base import PandasObject, FrozenList, FrozenNDArray, IndexOpsMixin, _shared_docs, PandasDelegate
1818
from pandas.util.decorators import (Appender, Substitution, cache_readonly,
1919
deprecate, deprecate_kwarg)
@@ -26,6 +26,9 @@
2626
from pandas.core.config import get_option
2727
from pandas.io.common import PerformanceWarning
2828

29+
30+
31+
2932
# simplify
3033
default_pprint = lambda x, max_seq_items=None: com.pprint_thing(x,
3134
escape_chars=('\t', '\r', '\n'),
@@ -973,7 +976,9 @@ def _convert_list_indexer(self, keyarr, kind=None):
973976
and we have a mixed index (e.g. number/labels). figure out
974977
the indexer. return None if we can't help
975978
"""
976-
if (kind is None or kind in ['iloc','ix']) and (is_integer_dtype(keyarr) and not self.is_floating()):
979+
if (kind is None or kind in ['iloc', 'ix']) and (
980+
is_integer_dtype(keyarr) and not self.is_floating() and not com.is_period_arraylike(keyarr)):
981+
977982
if self.inferred_type != 'integer':
978983
keyarr = np.where(keyarr < 0,
979984
len(self) + keyarr, keyarr)

pandas/tests/test_index.py

+8
Original file line numberDiff line numberDiff line change
@@ -3254,6 +3254,14 @@ def test_repeat(self):
32543254
self.assert_index_equal(res, exp)
32553255
self.assertEqual(res.freqstr, 'D')
32563256

3257+
def test_period_index_indexer(self):
3258+
3259+
#GH4125
3260+
idx = pd.period_range('2002-01','2003-12', freq='M')
3261+
df = pd.DataFrame(pd.np.random.randn(24,10), index=idx)
3262+
self.assert_frame_equal(df, df.ix[idx])
3263+
self.assert_frame_equal(df, df.ix[list(idx)])
3264+
32573265

32583266
class TestTimedeltaIndex(DatetimeLike, tm.TestCase):
32593267
_holder = TimedeltaIndex

0 commit comments

Comments
 (0)