-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: loc/ix indexers with empty list key lose names of respective axes #6552
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
Comments
…merrr/pandas into immerrr-fix-fancy-indexing-empty-list Conflicts: doc/source/release.rst
This happens because In [24]: idx = pd.Index(list('abc'), name='foobar')
In [25]: idx.names
Out[25]: FrozenList([u'foobar'])
In [27]: idx.reindex([])[0].names
Out[27]: FrozenList([None])
In [28]: idx.reindex(list('abc'))[0].names
Out[28]: FrozenList([None])
In [29]: idx.reindex(idx)[0].names
Out[29]: FrozenList([u'foobar'])
In [30]: idx.reindex(pd.Index([], name='xyzzy'))[0].names
Out[30]: FrozenList([u'xyzzy']) I think it's more appropriate to preserve names unless the target iterable is an Index itself and in that case its names should be used. On an unrelated topic, the same logic may be applied to other metadata, too, like timezone. |
@immerrr doable for 0.15.0? |
Yes, it is. |
On second thought, let's reiterate on that part of my message:
If the user has a proper Index with name and whatnot to be used instead of the old one, they should just assign the location to the new value, not doing reindexing. If they reindex, they probably only care about elements and their order to be changed, so the metadata should probably stay. Also, there may be element-related metadata (e.g. tz and freq) as opposed to index-related metadata (e.g. names) and probably only the last is worth preserving. @jreback what do you think? |
its not hard to preserve the meta data by default (and i think it should happen)
in this case null out the freq (which I think is right). addtl args are ignored in the constructor so this works for all index types |
Ok, and what about idx = pd.date_range(..., tz='UTC')
idx2 = idx.reindex(pd.date_range(..., tz='US/Pacific') What about |
I think you may need to check for that though prob should allow a naive tz to reindex a tz-aware as if they were the same |
though most of the combination ops coerce to utc before doing anything (intersection / union) so prob should raise is the tz are different (and not utc / naive) |
@immerrr pr for this? |
Will do this sometime week. I will only preserve name as there's some debate in tz-related ticket and freq should be re-inferred anyway. |
@immerrr thanks, yep tz-compat is in that other issue |
@jreback, just to be sure, we're changing |
Now, that I wrote this down it looks silly to add this inconsistency. OTOH, changing NDFrame.reindex behaviour right before a release doesn't feel right either. I'm going to implement name preservation for cases when indexer is not an Index as originally intended and will create a discussion issue afterwards. |
This issue was encountered when fixing #6536. It seems that
.loc
indexer with empty list key seems to lose names of respective axes:It's not important, but currently #6551 has two tests skipped because of this bug.
The text was updated successfully, but these errors were encountered: