-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: add test for .loc indexing Index type preservation #29533
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
TST: add test for .loc indexing Index type preservation #29533
Conversation
pandas/tests/frame/test_indexing.py
Outdated
@@ -1944,6 +1944,29 @@ def test_set_value_resize(self, float_frame): | |||
with pytest.raises(ValueError, match=msg): | |||
res3._set_value("foobar", "baz", "sam") | |||
|
|||
def test_loc_indexing_preserves_index_dtype(self): |
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 you mention categorical in the title?
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.
Thanks, @mroeschke - done.
pandas/tests/frame/test_indexing.py
Outdated
), | ||
) | ||
|
||
result_1 = df.index.levels[0] |
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 you write this like
expected=
result=
tm.assert_index_equal....
result=
tm.assert_index_equal....
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.
Thanks, @jreback - done.
pandas/tests/frame/test_indexing.py
Outdated
@@ -1944,6 +1944,29 @@ def test_set_value_resize(self, float_frame): | |||
with pytest.raises(ValueError, match=msg): | |||
res3._set_value("foobar", "baz", "sam") | |||
|
|||
def test_loc_indexing_preserves_index_category_dtype(self): |
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 you move this to: TestDataFrameIndexingCategorical
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.
Thanks, @jreback - unfortunately, I couldn't find tests/frame/indexing/test_...
, that's why I put the test in tests/frame/test_indexing.py
.
However, there seems to be a slight inconsistency in the tests/frame/
and tests/series/
structure as there's a indexing
subfolder in series
but not in frame
.
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.
this is a class name in the current file
However, there seems to be a slight inconsistency in the tests/frame/ and tests/series/ structure as there's a indexing subfolder in series but not in frame.
yes I know, there is an issue about fixing this (happy to have a PR), but orthogonal to this one.
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.
Ah, I see - moved the test there. Thanks
5423fde
to
8e3d5dd
Compare
8e3d5dd
to
3a87880
Compare
pandas/tests/frame/test_indexing.py
Outdated
@@ -1944,6 +1944,29 @@ def test_set_value_resize(self, float_frame): | |||
with pytest.raises(ValueError, match=msg): | |||
res3._set_value("foobar", "baz", "sam") | |||
|
|||
def test_loc_indexing_preserves_index_category_dtype(self): |
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.
this is a class name in the current file
However, there seems to be a slight inconsistency in the tests/frame/ and tests/series/ structure as there's a indexing subfolder in series but not in frame.
yes I know, there is an issue about fixing this (happy to have a PR), but orthogonal to this one.
thanks @ganevgv |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff