Skip to content

Commit 0452a41

Browse files
committed
move test and compare with expected df
1 parent 40a99dd commit 0452a41

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

pandas/tests/dtypes/test_dtypes.py

-7
Original file line numberDiff line numberDiff line change
@@ -998,10 +998,3 @@ def test_period_dtype_compare_to_string():
998998
dtype = PeriodDtype(freq="M")
999999
assert (dtype == "period[M]") is True
10001000
assert (dtype != "period[M]") is False
1001-
1002-
1003-
def test_column_not_loses_categorical_when_using_loc():
1004-
# GH16360
1005-
df = pd.DataFrame({"A": [1]})
1006-
df.loc[:, "B"] = Categorical(["a"])
1007-
assert is_categorical_dtype(df["B"])

pandas/tests/frame/indexing/test_categorical.py

+9
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,12 @@ def test_loc_indexing_preserves_index_category_dtype(self):
386386

387387
result = df.loc[["a"]].index.levels[0]
388388
tm.assert_index_equal(result, expected)
389+
390+
391+
def test_column_not_loses_categorical_when_using_loc():
392+
# GH16360
393+
result = DataFrame({"A": [1]})
394+
result.loc[:, "B"] = Categorical(["b"])
395+
expected = DataFrame({"A": [1], "B": ["b"]})
396+
expected["B"] = expected["B"].astype("category")
397+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)