-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix df.loc slice support #18703
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whatsnew 0.22
@@ -239,6 +239,15 @@ def test_iloc_getitem_multiindex(self): | |||
xp = mi_labels.ix['j'].ix[:, 'j'].ix[0, 0] | |||
assert rs == xp | |||
|
|||
# GH8856 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make separate test
@@ -2097,7 +2097,9 @@ def _maybe_to_slice(loc): | |||
mask[loc] = True | |||
return mask | |||
|
|||
if not isinstance(key, tuple): | |||
if isinstance(key, slice): |
There was a problem hiding this comment.
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
@@ -278,6 +287,15 @@ def test_loc_multiindex(self): | |||
xp = mi_int.ix[4] | |||
tm.assert_frame_equal(rs, xp) | |||
|
|||
# GH8856 | |||
s = pd.Series(np.arange(10), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(.iloc
vs. .loc
)
@@ -239,6 +239,15 @@ def test_iloc_getitem_multiindex(self): | |||
xp = mi_labels.ix['j'].ix[:, 'j'].ix[0, 0] | |||
assert rs == xp | |||
|
|||
# GH8856 | |||
s = pd.Series(np.arange(10), | |||
pd.MultiIndex.from_product(([0, 1], list('abcde')))) |
There was a problem hiding this comment.
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
@jreback Oops, sorry! I overlooked another test. Input:s = pd.Series(np.arange(8), pd.MultiIndex.from_product(([0, 1, 2, 3], list('ab'))))
s.loc[::2] = 200
s Output:
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:
|
@toobaz if you'd have a look |
I think slicing by string is not good since |
@Licht-T : I'm confused. Unless I'm missing anything, your changes to code are limited to
... ? |
closing as stale. ping if you want to update. |
git diff upstream/master -u -- "*.py" | flake8 --diff