@@ -1022,14 +1022,14 @@ def f():
10221022 def test_remove_unused_categories (self ):
10231023 c = Categorical (["a" , "b" , "c" , "d" , "a" ],
10241024 categories = ["a" , "b" , "c" , "d" , "e" ])
1025- exp_categories_all = np . array (["a" , "b" , "c" , "d" , "e" ])
1026- exp_categories_dropped = np . array (["a" , "b" , "c" , "d" ])
1025+ exp_categories_all = Index (["a" , "b" , "c" , "d" , "e" ])
1026+ exp_categories_dropped = Index (["a" , "b" , "c" , "d" ])
10271027
10281028 self .assert_numpy_array_equal (c .categories , exp_categories_all )
10291029
10301030 res = c .remove_unused_categories ()
1031- self .assert_numpy_array_equal (res .categories , exp_categories_dropped )
1032- self .assert_numpy_array_equal (c .categories , exp_categories_all )
1031+ self .assert_index_equal (res .categories , exp_categories_dropped )
1032+ self .assert_index_equal (c .categories , exp_categories_all )
10331033
10341034 res = c .remove_unused_categories (inplace = True )
10351035 self .assert_numpy_array_equal (c .categories , exp_categories_dropped )
@@ -1039,15 +1039,18 @@ def test_remove_unused_categories(self):
10391039 c = Categorical (["a" , "b" , "c" , np .nan ],
10401040 categories = ["a" , "b" , "c" , "d" , "e" ])
10411041 res = c .remove_unused_categories ()
1042- self .assert_numpy_array_equal (res .categories ,
1043- np .array (["a" , "b" , "c" ]))
1044- self .assert_numpy_array_equal (c .categories , exp_categories_all )
1042+ self .assert_index_equal (res .categories ,
1043+ Index (np .array (["a" , "b" , "c" ])))
1044+ exp_codes = np .array ([0 , 1 , 2 , - 1 ], dtype = np .int8 )
1045+ self .assert_numpy_array_equal (res .codes , exp_codes )
1046+ self .assert_index_equal (c .categories , exp_categories_all )
10451047
10461048 val = ['F' , np .nan , 'D' , 'B' , 'D' , 'F' , np .nan ]
10471049 cat = pd .Categorical (values = val , categories = list ('ABCDEFG' ))
10481050 out = cat .remove_unused_categories ()
1049- self .assert_numpy_array_equal (out .categories , ['B' , 'D' , 'F' ])
1050- self .assert_numpy_array_equal (out .codes , [2 , - 1 , 1 , 0 , 1 , 2 , - 1 ])
1051+ self .assert_index_equal (out .categories , Index (['B' , 'D' , 'F' ]))
1052+ exp_codes = np .array ([2 , - 1 , 1 , 0 , 1 , 2 , - 1 ], dtype = np .int8 )
1053+ self .assert_numpy_array_equal (out .codes , exp_codes )
10511054 self .assertEqual (out .get_values ().tolist (), val )
10521055
10531056 alpha = list ('abcdefghijklmnopqrstuvwxyz' )
0 commit comments