Skip to content

TST: add test to verify column does not lose categorical type when using loc #37988

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
merged 4 commits into from
Nov 23, 2020

Conversation

fgebhart
Copy link
Contributor

Added a test to verify the behavior described in issue #16360. However, I'm not 100% sure about the location of the test.

@fgebhart fgebhart changed the title add test to verify column does not lose categorical type when using loc TST: add test to verify column does not lose categorical type when using loc Nov 21, 2020
Copy link
Member

@arw2019 arw2019 left a comment

Choose a reason for hiding this comment

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

Thanks @fgebhart for the PR!

Not 100% sure about the location either but pandas/tests/indexing/test_coercion.py could be the place

@jreback jreback added Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves labels Nov 21, 2020
@fgebhart
Copy link
Contributor Author

failed test is unrelated to my changes - do you collect flaky tests somewhere? i.e. pandas/tests/plotting/frame/test_frame.py::TestDataFramePlots::test_area_lim

@fgebhart fgebhart force-pushed the column_loses_category branch from 5f16e01 to 353bce1 Compare November 22, 2020 14:35
@jreback jreback added this to the 1.2 milestone Nov 23, 2020
@@ -1285,6 +1286,14 @@ def test_loc_setitem_datetime_keys_cast(self):
expected = DataFrame({"one": [100.0, 200.0]}, index=[dt1, dt2])
tm.assert_frame_equal(df, expected)

def test_loc_setitem_categorical_column_retains_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 add the ordered fixture (just include it in the arg list and pass to Categorical), it should just work. ping on green.

@jreback jreback merged commit 2c1e981 into pandas-dev:master Nov 23, 2020
@jreback
Copy link
Contributor

jreback commented Nov 23, 2020

thanks @fgebhart very nice

@fgebhart fgebhart deleted the column_loses_category branch November 23, 2020 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Column loses category when using .loc for a one row dataframe
4 participants