We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 25a1d91 commit 2c1e981Copy full SHA for 2c1e981
pandas/tests/indexing/test_loc.py
@@ -12,6 +12,7 @@
12
13
import pandas as pd
14
from pandas import (
15
+ Categorical,
16
CategoricalIndex,
17
DataFrame,
18
Index,
@@ -1319,6 +1320,13 @@ def test_loc_setitem_datetime_keys_cast(self):
1319
1320
expected = DataFrame({"one": [100.0, 200.0]}, index=[dt1, dt2])
1321
tm.assert_frame_equal(df, expected)
1322
1323
+ def test_loc_setitem_categorical_column_retains_dtype(self, ordered):
1324
+ # GH16360
1325
+ result = DataFrame({"A": [1]})
1326
+ result.loc[:, "B"] = Categorical(["b"], ordered=ordered)
1327
+ expected = DataFrame({"A": [1], "B": Categorical(["b"], ordered=ordered)})
1328
+ tm.assert_frame_equal(result, expected)
1329
+
1330
1331
class TestLocCallable:
1332
def test_frame_loc_getitem_callable(self):
0 commit comments