Skip to content

BUG: xs with drop_level=True with a fully specified tuples buggy #6507

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

Open
jreback opened this issue Feb 28, 2014 · 4 comments
Open

BUG: xs with drop_level=True with a fully specified tuples buggy #6507

jreback opened this issue Feb 28, 2014 · 4 comments
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex

Comments

@jreback
Copy link
Contributor

jreback commented Feb 28, 2014

related #6501

In [1]: n=23

In [2]: df = pd.DataFrame({'a':np.append(np.random.randint(0,10,n), -1),
   ...:                    'b':np.append(np.random.randint(0,10,n), -1),
   ...:                    'c':np.append(np.random.randint(0,10,n), -1),
   ...:                    'value':np.random.randint(0,100,n+1)})
In [3]: df.set_index(['a','b','c'], inplace=True)

In [4]: df.sortlevel(inplace = True)

In [7]: df.xs((-1,-1,-1),drop_level=True)
Out[7]: 
value    40
Name: (-1, -1, -1), dtype: int64

In [8]: df.xs((-1,-1),drop_level=True)
Out[8]: 
    value
c        
-1     40

[1 rows x 1 columns]
@hayd
Copy link
Contributor

hayd commented Mar 1, 2014

Pretty racy example...

@hayd
Copy link
Contributor

hayd commented Mar 1, 2014

So it becomes a Series when it should be a frame?

Also, incorrect for drop_level=False, presumably same reason.

In [21]: df.xs((-1,-1, -1),drop_level=False)
Out[21]:
value    59
Name: (-1, -1, -1), dtype: int64

expected = df.xs((-1,-1),drop_level=False)

Annoying no way to get from Series (name) to DataFrame with correct mi... maybe we could use namedtuple (ag, but this would fail on dupe names :S)

@jreback
Copy link
Contributor Author

jreback commented Mar 1, 2014

I was thinking that this should be a scalar
but looking again this example only has 1 column
so it should be a series always I think

this is equiv to
df.loc[indexer]

drop_level=False with a fully specified tuple is just
like passing [indexer]

hmm one could argue that it should be a scalar
but what if their are multiple return values then it had to be a series

@hayd
Copy link
Contributor

hayd commented Mar 1, 2014

it's weird cos everything is inconsistent (the index goes from having 3 levels to 2 levels to 1 level to ...er). IMO should be DataFrame as could have more columns.

Confusing.

@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 3, 2015
@datapythonista datapythonista modified the milestones: Contributions Welcome, Someday Jul 8, 2018
@jbrockmendel jbrockmendel added the Indexing Related to indexing on series/frames, not to indexes themselves label Sep 22, 2020
@mroeschke mroeschke removed this from the Someday milestone Oct 13, 2022
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 MultiIndex
Projects
None yet
Development

No branches or pull requests

5 participants