Skip to content

Commit 5f16e01

Browse files
committed
move again and rename function
1 parent 0452a41 commit 5f16e01

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

pandas/tests/frame/indexing/test_categorical.py

-9
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,3 @@ 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)

pandas/tests/indexing/test_loc.py

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import pandas as pd
1414
from pandas import (
15+
Categorical,
1516
CategoricalIndex,
1617
DataFrame,
1718
Index,
@@ -1285,6 +1286,14 @@ def test_loc_setitem_datetime_keys_cast(self):
12851286
expected = DataFrame({"one": [100.0, 200.0]}, index=[dt1, dt2])
12861287
tm.assert_frame_equal(df, expected)
12871288

1289+
def test_loc_setitem_categorical_column_retains_dtype(self):
1290+
# GH16360
1291+
result = DataFrame({"A": [1]})
1292+
result.loc[:, "B"] = Categorical(["b"])
1293+
expected = DataFrame({"A": [1], "B": ["b"]})
1294+
expected["B"] = expected["B"].astype("category")
1295+
tm.assert_frame_equal(result, expected)
1296+
12881297

12891298
class TestLocCallable:
12901299
def test_frame_loc_getitem_callable(self):

0 commit comments

Comments
 (0)