Skip to content

API: should .loc be as strict as .ix in tuple indexing? #3390

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
jreback opened this issue Apr 18, 2013 · 5 comments
Closed

API: should .loc be as strict as .ix in tuple indexing? #3390

jreback opened this issue Apr 18, 2013 · 5 comments
Labels
Ideas Long-Term Enhancement Discussions Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Apr 18, 2013

from ML

https://groups.google.com/forum/?fromgroups=#!topic/pydata/fzPGjVrj9lU

df = pd.DataFrame.from_items([('a', [1,2]), ('b', ([3,4]))])
df.index = pd.MultiIndex.from_tuples([('A', 'B'),('C', 'D')],
        names=['k1', 'k2'])

# A dataframe, with a multiindex:
>>> df
       a  b
k1 k2
A  B   1  3
C  D   2  4

.ix[('A','B')] succeeds
.ix['A','B'] succeeds as the A, B is tried as a tuple (.ix tries hard here)

propose that we change .loc to disallow the 2nd case and instead raise a KeyError
its more 'strict'

@ghost
Copy link

ghost commented Apr 18, 2013

IIRC, that's a python wart in __getitem__, those two cases look identical
to the callee:

In [2]: class A(object):
   ...:     def __getitem__(self,*args):
   ...:         print args
   ...: a=A()

In [3]: a['1','2']
(('1', '2'),)

In [4]: a[('1','2')]
(('1', '2'),)

@jreback
Copy link
Contributor Author

jreback commented Apr 18, 2013

@y-p ahh yes.........I guess there is not a way to disambiguate if the tuple exists in a mi in the index, versus the case where the individual elements existing in both an index and a column......

@ghost
Copy link

ghost commented Apr 18, 2013

yeah. I think in some places in pandas the type is used to dismbiguate behaviour
(tuple vs. list trigger different code paths). I noticed a while back that the semantics
of sets aren't exploited yet. Maybe we can put that to good use someday
(with slighly verbose syntax on python 2.6), as if pandas' signature overloading wasn't
ridiculous already

What should .iloc[{1,2,3,5}] mean? random permutation of rows?
label-uniquified slice? foo? bar?

@jreback
Copy link
Contributor Author

jreback commented Apr 18, 2013

:)....going to push to 0.12...to see if we want to change the API at all

@jreback
Copy link
Contributor Author

jreback commented Sep 22, 2013

closing as impossible to disambiguate w/o new syntax which makes things even more magical than they are now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ideas Long-Term Enhancement Discussions Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

1 participant