@@ -1311,26 +1311,27 @@ def test_replace_value_category_type(self):
1311
1311
expected = DataFrame (data = expected_dict ).astype (
1312
1312
{"col2" : "category" , "col4" : "category" }
1313
1313
)
1314
+ # GH#61074
1314
1315
expected ["col2" ] = expected ["col2" ].cat .reorder_categories (
1315
- ["a" , "b" , "c" , "z" ], ordered = True
1316
+ ["a" , "b" , "c" , "z" ], ordered = False
1316
1317
)
1317
1318
expected ["col4" ] = expected ["col4" ].cat .reorder_categories (
1318
- ["cat1" , "catX" , "cat3" , "cat4" ], ordered = True
1319
- )
1320
-
1321
- # replace values in input dataframe
1322
- input_df = input_df . apply (
1323
- lambda x : x . astype ( "category" ). cat . rename_categories ({ "d" : "z" })
1324
- )
1325
- input_df = input_df . apply (
1326
- lambda x : x . astype ( "category" ). cat . rename_categories ({ "obj1" : "obj9" })
1327
- )
1328
- result = input_df . apply (
1329
- lambda x : x .astype ("category" ). cat . rename_categories ({ "cat2" : "catX" } )
1330
- )
1331
-
1332
- result = result . astype ({"col1 " : "int64" , "col3" : "float64" , "col5" : "str " })
1333
- tm . assert_frame_equal ( result , expected )
1319
+ ["cat1" , "catX" , "cat3" , "cat4" ], ordered = False
1320
+ )
1321
+
1322
+ # replace values in input dataframe
1323
+ # GH#61074
1324
+ msg = "The 'category' dtype is being set to ordered=False by default."
1325
+ for col in [ "col2" , "col4" ]:
1326
+ if input_df [ col ]. dtype . ordered :
1327
+ with tm . assert_produces_warning ( DeprecationWarning , match = msg ):
1328
+ input_df [ col ] = input_df [ col ]. astype ( "category" )
1329
+
1330
+ input_df [ "col5" ] = input_df [ "col5" ] .astype ("category" )
1331
+
1332
+ input_df [ "col2" ] = input_df [ "col2" ]. cat . rename_categories ({ "d" : "z" })
1333
+ input_df [ "col4" ] = input_df [ "col4" ]. cat . rename_categories ({"cat2 " : "catX " })
1334
+ input_df [ "col5" ] = input_df [ "col5" ]. cat . rename_categories ({ "obj1" : "obj9" } )
1334
1335
1335
1336
def test_replace_dict_category_type (self ):
1336
1337
"""
0 commit comments