Skip to content

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

Merged

Conversation

ganevgv
Copy link
Contributor

@ganevgv ganevgv commented Nov 10, 2019

@@ -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):
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, @mroeschke - done.

@mroeschke mroeschke added Indexing Related to indexing on series/frames, not to indexes themselves Testing pandas testing functions or related to the test suite labels Nov 10, 2019
),
)

result_1 = df.index.levels[0]
Copy link
Contributor

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....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, @jreback - done.

@@ -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):
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

@ganevgv ganevgv force-pushed the tests/add_loc_index_preserves_dtype_test branch 2 times, most recently from 5423fde to 8e3d5dd Compare November 12, 2019 00:15
@ganevgv ganevgv force-pushed the tests/add_loc_index_preserves_dtype_test branch from 8e3d5dd to 3a87880 Compare November 12, 2019 00:47
@@ -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):
Copy link
Contributor

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.

@jreback jreback added this to the 1.0 milestone Nov 12, 2019
@jreback jreback merged commit e5c3907 into pandas-dev:master Nov 13, 2019
@jreback
Copy link
Contributor

jreback commented Nov 13, 2019

thanks @ganevgv

Reksbril pushed a commit to Reksbril/pandas that referenced this pull request Nov 18, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
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 Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: .loc indexing not preserving Index type
3 participants