@@ -63,27 +63,39 @@ def test_factorize_complex(self):
63
63
expected_uniques = np .array ([(1 + 0j ), (2 + 0j ), (2 + 1j )], dtype = complex )
64
64
tm .assert_numpy_array_equal (uniques , expected_uniques )
65
65
66
+ @pytest .mark .parametrize ("index_or_series_obj" ,
67
+ [
68
+ [1 , 2 , 3 ],
69
+ ["a" , "b" , "c" ],
70
+ [0 , "a" , 1 , "b" , 2 , "c" ]
71
+ ])
72
+ @pytest .mark .parametrize ("sort" , [True , False ])
66
73
def test_factorize (self , index_or_series_obj , sort ):
67
- obj = index_or_series_obj
74
+ obj = Index (index_or_series_obj )
75
+
76
+ if obj .empty :
77
+ pytest .skip ("Skipping test for empty Index" )
78
+
79
+ if obj .name == "mixed-int-string" or obj .name is None :
80
+ pytest .skip ("Skipping test for mixed-int-string due to unsupported comparison between str and int" )
81
+
82
+
68
83
result_codes , result_uniques = obj .factorize (sort = sort )
69
84
70
85
constructor = Index
71
- if isinstance (obj , MultiIndex ):
72
- constructor = MultiIndex .from_tuples
73
86
expected_arr = obj .unique ()
74
87
if expected_arr .dtype == np .float16 :
75
88
expected_arr = expected_arr .astype (np .float32 )
76
89
expected_uniques = constructor (expected_arr )
77
- if (
78
- isinstance (obj , Index )
79
- and expected_uniques .dtype == bool
80
- and obj .dtype == object
81
- ):
90
+
91
+ if expected_uniques .dtype == bool and obj .dtype == object :
82
92
expected_uniques = expected_uniques .astype (object )
83
93
94
+
84
95
if sort :
85
96
expected_uniques = expected_uniques .sort_values ()
86
97
98
+
87
99
# construct an integer ndarray so that
88
100
# `expected_uniques.take(expected_codes)` is equal to `obj`
89
101
expected_uniques_list = list (expected_uniques )
0 commit comments