Skip to content

Conversation

@Licht-T
Copy link
Contributor

@Licht-T Licht-T commented Dec 9, 2017

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whatsnew 0.22

xp = mi_labels.ix['j'].ix[:, 'j'].ix[0, 0]
assert rs == xp

# GH8856
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make separate test

return mask

if not isinstance(key, tuple):
if isinstance(key, slice):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can u add some comments here

tm.assert_frame_equal(rs, xp)

# GH8856
s = pd.Series(np.arange(10),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a duplicate of the other test?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(.iloc vs. .loc)


# GH8856
s = pd.Series(np.arange(10),
pd.MultiIndex.from_product(([0, 1], list('abcde'))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can u add several cases using slices

also if other testing of slice u can pull to this section

@Licht-T
Copy link
Contributor Author

Licht-T commented Dec 9, 2017

@jreback Oops, sorry! I overlooked another test.
The MultiIndex loc slicing work at the first level.
https://github.com/pandas-dev/pandas/blob/master/pandas/tests/test_multilevel.py#L1829

Input:

s = pd.Series(np.arange(8), pd.MultiIndex.from_product(([0, 1, 2, 3], list('ab')))) s.loc[::2] = 200 s

Output:

0 a 200 b 200 1 a 2 b 3 2 a 200 b 200 3 a 6 b 7 

But, this returns the crazy result.

Input:

index = pd.MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'], ['one', 'two','three']], labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]], names=['first', 'second']) frame = pd.DataFrame(np.random.randn(10, 3), index=index, columns=pd.Index(['A', 'B', 'C'], name='exp')) frame.loc['foo':'bar':4]

Output:

exp A B C first second foo one 0.870785 1.900457 -0.907938 bar two -0.290714 -0.211697 -0.957994 
@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex labels Dec 9, 2017
@jreback
Copy link
Contributor

jreback commented Dec 9, 2017

@toobaz if you'd have a look

@Licht-T
Copy link
Contributor Author

Licht-T commented Dec 9, 2017

I think slicing by string is not good since slice seems not supporting to handle string.

@toobaz
Copy link
Member

toobaz commented Dec 12, 2017

@Licht-T : I'm confused. Unless I'm missing anything, your changes to code are limited to pd.MultiIndex.get_loc, but in up-to-date master,

... ?

@jreback
Copy link
Contributor

jreback commented Feb 10, 2018

closing as stale. ping if you want to update.

@jreback jreback closed this Feb 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex

3 participants