@@ -256,7 +256,7 @@ def test_mode_numerical(self, dropna, expected1, expected2, expected3):
256256
257257 @pytest .mark .parametrize ('dropna, expected1, expected2, expected3' , [
258258 (True , ['b' ], ['bar' ], ['nan' ]),
259- (False , ['b' ], ['bar' , np .nan ], ['nan' ])
259+ (False , ['b' ], [np .nan ], ['nan' ])
260260 ])
261261 def test_mode_str_obj (self , dropna , expected1 , expected2 , expected3 ):
262262 # Test string and object types.
@@ -266,7 +266,7 @@ def test_mode_str_obj(self, dropna, expected1, expected2, expected3):
266266 expected1 = Series (expected1 , dtype = 'c' )
267267 tm .assert_series_equal (s .mode (dropna ), expected1 )
268268
269- data = ['foo' , 'bar' , 'bar' , np .nan , np .nan ]
269+ data = ['foo' , 'bar' , 'bar' , np .nan , np .nan , np . nan ]
270270
271271 s = Series (data , dtype = object )
272272 expected2 = Series (expected2 , dtype = object )
@@ -281,22 +281,22 @@ def test_mode_str_obj(self, dropna, expected1, expected2, expected3):
281281
282282 @pytest .mark .parametrize ('dropna, expected1, expected2' , [
283283 (True , ['foo' ], ['foo' ]),
284- (False , ['foo' ], ['foo' , np .nan ])
284+ (False , ['foo' ], [np .nan ])
285285 ])
286286 def test_mode_mixeddtype (self , dropna , expected1 , expected2 ):
287287 expected = Series (expected1 )
288288 s = Series ([1 , 'foo' , 'foo' ])
289289 tm .assert_series_equal (s .mode (dropna ), expected )
290290
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 ])
293293 result = s .mode (dropna ).sort_values ().reset_index (drop = True )
294294 tm .assert_series_equal (result , expected )
295295
296296 @pytest .mark .parametrize ('dropna, expected1, expected2' , [
297297 (True , ['1900-05-03' , '2011-01-03' , '2013-01-02' ],
298298 ['2011-01-03' , '2013-01-02' ]),
299- (False , [np .nan ], [' nan' , '2011-01-03' , '2013-01-02' ]),
299+ (False , [np .nan ], [np . nan , '2011-01-03' , '2013-01-02' ]),
300300 ])
301301 def test_mode_datetime (self , dropna , expected1 , expected2 ):
302302 expected1 = Series (expected1 , dtype = 'M8[ns]' )
@@ -312,7 +312,7 @@ def test_mode_datetime(self, dropna, expected1, expected2):
312312
313313 @pytest .mark .parametrize ('dropna, expected1, expected2' , [
314314 (True , ['-1 days' , '0 days' , '1 days' ], ['2 min' , '1 day' ]),
315- (False , [' nan' ], [' nan' , '2 min' , '1 day' ]),
315+ (False , [np . nan ], [np . nan , '2 min' , '1 day' ]),
316316 ])
317317 def test_mode_timedelta (self , dropna , expected1 , expected2 ):
318318 # gh-5986: Test timedelta types.
@@ -363,6 +363,21 @@ def test_mode_intoverflow(self, dropna, expected1, expected2):
363363 s = Series ([1 , 2 ** 63 ], dtype = np .uint64 )
364364 tm .assert_series_equal (s .mode (dropna ), expected2 )
365365
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+
366381 def test_prod (self ):
367382 self ._check_stat_op ('prod' , np .prod )
368383
0 commit comments