@@ -256,7 +256,7 @@ def test_mode_numerical(self, dropna, expected1, expected2, expected3):
256
256
257
257
@pytest .mark .parametrize ('dropna, expected1, expected2, expected3' , [
258
258
(True , ['b' ], ['bar' ], ['nan' ]),
259
- (False , ['b' ], ['bar' , np .nan ], ['nan' ])
259
+ (False , ['b' ], [np .nan ], ['nan' ])
260
260
])
261
261
def test_mode_str_obj (self , dropna , expected1 , expected2 , expected3 ):
262
262
# Test string and object types.
@@ -266,7 +266,7 @@ def test_mode_str_obj(self, dropna, expected1, expected2, expected3):
266
266
expected1 = Series (expected1 , dtype = 'c' )
267
267
tm .assert_series_equal (s .mode (dropna ), expected1 )
268
268
269
- data = ['foo' , 'bar' , 'bar' , np .nan , np .nan ]
269
+ data = ['foo' , 'bar' , 'bar' , np .nan , np .nan , np . nan ]
270
270
271
271
s = Series (data , dtype = object )
272
272
expected2 = Series (expected2 , dtype = object )
@@ -281,15 +281,15 @@ def test_mode_str_obj(self, dropna, expected1, expected2, expected3):
281
281
282
282
@pytest .mark .parametrize ('dropna, expected1, expected2' , [
283
283
(True , ['foo' ], ['foo' ]),
284
- (False , ['foo' ], ['foo' , np .nan ])
284
+ (False , ['foo' ], [np .nan ])
285
285
])
286
286
def test_mode_mixeddtype (self , dropna , expected1 , expected2 ):
287
287
expected = Series (expected1 )
288
288
s = Series ([1 , 'foo' , 'foo' ])
289
289
tm .assert_series_equal (s .mode (dropna ), expected )
290
290
291
- expected = Series (expected2 )
292
- s = Series ([1 , 'foo' , 'foo' , np .nan , np .nan ])
291
+ expected = Series (expected2 , dtype = object )
292
+ s = Series ([1 , 'foo' , 'foo' , np .nan , np .nan , np . nan ])
293
293
result = s .mode (dropna ).sort_values ().reset_index (drop = True )
294
294
tm .assert_series_equal (result , expected )
295
295
@@ -363,6 +363,21 @@ def test_mode_intoverflow(self, dropna, expected1, expected2):
363
363
s = Series ([1 , 2 ** 63 ], dtype = np .uint64 )
364
364
tm .assert_series_equal (s .mode (dropna ), expected2 )
365
365
366
+ @pytest .mark .parametrize ('dropna, expected' , [
367
+ (False , ['foo' , np .nan ]),
368
+ ])
369
+ def test_mode_sortwarning (self , dropna , expected ):
370
+ # Check for the warning that is raised when the mode
371
+ # results cannot be sorted
372
+
373
+ expected = Series (expected )
374
+ s = Series ([1 , 'foo' , 'foo' , np .nan , np .nan ])
375
+
376
+ with tm .assert_produces_warning (UserWarning , check_stacklevel = False ):
377
+ result = s .mode (dropna ).sort_values ().reset_index (drop = True )
378
+
379
+ tm .assert_series_equal (result , expected )
380
+
366
381
def test_prod (self ):
367
382
self ._check_stat_op ('prod' , np .prod )
368
383
0 commit comments