Skip to content

Commit

Permalink
BUG: .ix with PeriodIndex isn't treated as integers, #4125
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty authored and jreback committed Sep 9, 2015
1 parent 724e15f commit 879f5e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
import datetime
import warnings
import operator

from functools import partial
from pandas.compat import range, zip, lrange, lzip, u, reduce, filter, map
from pandas import compat
import numpy as np

from sys import getsizeof

import numpy as np
import pandas.tslib as tslib
import pandas.lib as lib
import pandas.algos as _algos
import pandas.index as _index
from pandas.lib import Timestamp, Timedelta, is_datetime_array

from pandas.compat import range, zip, lrange, lzip, u, map
from pandas import compat
from pandas.core.base import PandasObject, FrozenList, FrozenNDArray, IndexOpsMixin, _shared_docs, PandasDelegate
from pandas.util.decorators import (Appender, Substitution, cache_readonly,
deprecate, deprecate_kwarg)
Expand All @@ -26,6 +26,9 @@
from pandas.core.config import get_option
from pandas.io.common import PerformanceWarning




# simplify
default_pprint = lambda x, max_seq_items=None: com.pprint_thing(x,
escape_chars=('\t', '\r', '\n'),
Expand Down Expand Up @@ -973,7 +976,9 @@ def _convert_list_indexer(self, keyarr, kind=None):
and we have a mixed index (e.g. number/labels). figure out
the indexer. return None if we can't help
"""
if (kind is None or kind in ['iloc','ix']) and (is_integer_dtype(keyarr) and not self.is_floating()):
if (kind is None or kind in ['iloc', 'ix']) and (
is_integer_dtype(keyarr) and not self.is_floating() and not com.is_period_arraylike(keyarr)):

if self.inferred_type != 'integer':
keyarr = np.where(keyarr < 0,
len(self) + keyarr, keyarr)
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3254,6 +3254,14 @@ def test_repeat(self):
self.assert_index_equal(res, exp)
self.assertEqual(res.freqstr, 'D')

def test_period_index_indexer(self):

#GH4125
idx = pd.period_range('2002-01','2003-12', freq='M')
df = pd.DataFrame(pd.np.random.randn(24,10), index=idx)
self.assert_frame_equal(df, df.ix[idx])
self.assert_frame_equal(df, df.ix[list(idx)])


class TestTimedeltaIndex(DatetimeLike, tm.TestCase):
_holder = TimedeltaIndex
Expand Down

0 comments on commit 879f5e9

Please sign in to comment.