@@ -70,58 +70,46 @@ def test_mode(self, values, categories, exp_mode):
70
70
exp = Categorical (exp_mode , categories = categories , ordered = True )
71
71
tm .assert_categorical_equal (res , exp )
72
72
73
- def test_searchsorted (self ):
73
+ @pytest .mark .parametrize ("ordered" , [True , False ])
74
+ def test_searchsorted (self , ordered ):
74
75
# https://github.com/pandas-dev/pandas/issues/8420
75
76
# https://github.com/pandas-dev/pandas/issues/14522
76
77
77
- c1 = Categorical (['cheese' , 'milk' , 'apple' , 'bread' , 'bread' ],
78
- categories = ['cheese' , 'milk' , 'apple' , 'bread' ],
79
- ordered = True )
80
- s1 = Series (c1 )
81
- c2 = Categorical (['cheese' , 'milk' , 'apple' , 'bread' , 'bread' ],
82
- categories = ['cheese' , 'milk' , 'apple' , 'bread' ],
83
- ordered = False )
84
- s2 = Series (c2 )
78
+ c = Categorical (['cheese' , 'milk' , 'apple' , 'bread' , 'bread' ],
79
+ categories = ['cheese' , 'milk' , 'apple' , 'bread' ],
80
+ ordered = ordered )
81
+ s = Series (c )
85
82
86
83
# Searching for single item argument, side='left' (default)
87
- res_cat = c1 .searchsorted ('apple' )
88
- res_ser = s1 .searchsorted ('apple' )
84
+ res_cat = c .searchsorted ('apple' )
85
+ res_ser = s .searchsorted ('apple' )
89
86
exp = np .array ([2 ], dtype = np .intp )
90
87
tm .assert_numpy_array_equal (res_cat , exp )
91
88
tm .assert_numpy_array_equal (res_ser , exp )
92
89
93
90
# Searching for single item array, side='left' (default)
94
- res_cat = c1 .searchsorted (['bread' ])
95
- res_ser = s1 .searchsorted (['bread' ])
91
+ res_cat = c .searchsorted (['bread' ])
92
+ res_ser = s .searchsorted (['bread' ])
96
93
exp = np .array ([3 ], dtype = np .intp )
97
94
tm .assert_numpy_array_equal (res_cat , exp )
98
95
tm .assert_numpy_array_equal (res_ser , exp )
99
96
100
97
# Searching for several items array, side='right'
101
- res_cat = c1 .searchsorted (['apple' , 'bread' ], side = 'right' )
102
- res_ser = s1 .searchsorted (['apple' , 'bread' ], side = 'right' )
98
+ res_cat = c .searchsorted (['apple' , 'bread' ], side = 'right' )
99
+ res_ser = s .searchsorted (['apple' , 'bread' ], side = 'right' )
103
100
exp = np .array ([3 , 5 ], dtype = np .intp )
104
101
tm .assert_numpy_array_equal (res_cat , exp )
105
102
tm .assert_numpy_array_equal (res_ser , exp )
106
103
107
104
# Searching for a single value that is not from the Categorical
108
- pytest .raises (ValueError , lambda : c1 .searchsorted ('cucumber' ))
109
- pytest .raises (ValueError , lambda : s1 .searchsorted ('cucumber' ))
105
+ pytest .raises (ValueError , lambda : c .searchsorted ('cucumber' ))
106
+ pytest .raises (ValueError , lambda : s .searchsorted ('cucumber' ))
110
107
111
108
# Searching for multiple values one of each is not from the Categorical
112
109
pytest .raises (ValueError ,
113
- lambda : c1 .searchsorted (['bread' , 'cucumber' ]))
110
+ lambda : c .searchsorted (['bread' , 'cucumber' ]))
114
111
pytest .raises (ValueError ,
115
- lambda : s1 .searchsorted (['bread' , 'cucumber' ]))
116
-
117
- # searchsorted call for unordered Categorical
118
- pytest .raises (ValueError , lambda : c2 .searchsorted ('apple' ))
119
- pytest .raises (ValueError , lambda : s2 .searchsorted ('apple' ))
120
-
121
- with tm .assert_produces_warning (FutureWarning ):
122
- res = c1 .searchsorted (v = ['bread' ])
123
- exp = np .array ([3 ], dtype = np .intp )
124
- tm .assert_numpy_array_equal (res , exp )
112
+ lambda : s .searchsorted (['bread' , 'cucumber' ]))
125
113
126
114
def test_unique (self ):
127
115
# categories are reordered based on value when ordered=False
0 commit comments