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

Conversation

max-sixty
Copy link
Contributor

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?

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

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type labels Sep 7, 2015
@@ -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)):
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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 ints. 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

Copy link
Contributor

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

@jreback jreback added this to the 0.17.0 milestone Sep 7, 2015
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.

@jreback
Copy link
Contributor

jreback commented Sep 9, 2015

pls add a whatsnew note

@jreback
Copy link
Contributor

jreback commented Sep 9, 2015

merged via 879f5e9

thanks!

(I changed this slightly in another commit). is_array_period_like does inference on the object and thus could be slow potentially

@max-sixty
Copy link
Contributor Author

Cheers @jreback!

@max-sixty max-sixty deleted the period-index-er branch December 8, 2015 03:52
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants