Skip to content

BUG: .ix with PeriodIndex is fixed #11015

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
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stuff is PyCharm - I can revert if you want

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)):

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on 2nd thought, this is going to cause a perf issue ,change this to isinstance(keyarr, ABCPeriodIndex) (you can import this at the top.

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 @@ -3221,6 +3221,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