File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change 12
12
13
13
import pandas as pd
14
14
from pandas import (
15
+ Categorical ,
15
16
CategoricalIndex ,
16
17
DataFrame ,
17
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 ])
1320
1321
tm .assert_frame_equal (df , expected )
1321
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
+
1322
1330
1323
1331
class TestLocCallable :
1324
1332
def test_frame_loc_getitem_callable (self ):
You can’t perform that action at this time.
0 commit comments