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
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import pandas as pd
from pandas import (
Categorical,
CategoricalIndex,
DataFrame,
Index,
Expand Down Expand Up @@ -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.

# GH16360
result = DataFrame({"A": [1]})
result.loc[:, "B"] = Categorical(["b"])
expected = DataFrame({"A": [1], "B": ["b"]})
expected["B"] = expected["B"].astype("category")
tm.assert_frame_equal(result, expected)


class TestLocCallable:
def test_frame_loc_getitem_callable(self):
Expand Down