@@ -114,6 +114,37 @@ def test_bins_not_monotonic():
114
114
cut (data , [0.1 , 1.5 , 1 , 10 ])
115
115
116
116
117
+ @pytest .mark .parametrize (
118
+ "data" ,
119
+ [
120
+ [0.2 , 1.4 , 2.5 , 6.2 , 9.7 , 2.1 ],
121
+ np .array ([0.2 , 1.4 , 2.5 , 6.2 , 9.7 , 2.1 , 2.575 ]),
122
+ np .array ([10 , 15 , 13 , 12 , 23 , 25 , 28 , 59 , 60 ]),
123
+ range (5 ),
124
+ ],
125
+ )
126
+ @pytest .mark .parametrize (
127
+ "bin_str" , ["auto" , "fd" , "doane" , "scott" , "stone" , "rice" , "sturges" , "sqrt" ]
128
+ )
129
+ def test_bins_from_string (data , bin_str ):
130
+ # we make sure calling cut(df, str) is equivalent
131
+ # to calling cut(df, bins=np.histogram_bin_edges(df,str))
132
+ expected = cut (data , bins = np .histogram_bin_edges (data , bins = bin_str ))
133
+ result = cut (data , bin_str )
134
+ tm .assert_categorical_equal (result , expected , check_dtype = False )
135
+
136
+
137
+ def test_bins_from_invalid_string ():
138
+ # we make sure calling cut(df, str) with invalid string
139
+ # throws an error
140
+ bin_str = "INVALID_STR"
141
+ msg = f"{ bin_str !r} is not a valid estimator for `bins`"
142
+ data = [0.2 , 1.4 , 2.5 , 6.2 , 9.7 , 2.1 ]
143
+
144
+ with pytest .raises (ValueError , match = msg ):
145
+ cut (data , bin_str )
146
+
147
+
117
148
@pytest .mark .parametrize (
118
149
"x, bins, expected" ,
119
150
[
0 commit comments