-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
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 |
There was a problem hiding this comment.
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
@@ -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 isinstance(keyarr, ABCPeriodIndex)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use com.is_period_arraylike
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
though you might simply be able to define _convert_list_indexer
in PeriodIndex
to handle this in a nicer way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree for most cases - when you have a PeriodIndex
and you supply another as an index.
But if you have an integer index and someone supplies a PeriodIndex
as the key, I don't think you want that resolving to its int
s. Does that make sense?
Would this be solved if we had a Period
dtype
? I couldn't find an open issue about that, but I think you've mentioned it a few times
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
period dtype would fix this but that's for the future
period right now is an integer dtype and that's the problem it's confused
b5544ca
to
099292e
Compare
099292e
to
225bb34
Compare
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)): | ||
|
There was a problem hiding this comment.
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.
pls add a whatsnew note |
merged via 879f5e9 thanks! (I changed this slightly in another commit). |
Cheers @jreback! |
Solves #4125
It doesn't feel like an elegant solution, but I think it works.
I think when Period gets its own dtype, these will all go away?