Skip to content

Commit 6b41f60

Browse files
committed
Test separately for warning and fix typos
1 parent 12feb01 commit 6b41f60

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

pandas/core/frame.py

+4
Original file line numberDiff line numberDiff line change
@@ -7113,6 +7113,10 @@ def quantile(self, q=0.5, axis=0, numeric_only=True,
71137113
a b
71147114
0.1 1.3 3.7
71157115
0.5 2.5 55.0
7116+
7117+
See Also
7118+
--------
7119+
pandas.core.window.Rolling.quantile
71167120
"""
71177121
self._check_percentile(q)
71187122

pandas/tests/series/test_analytics.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -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,15 +281,15 @@ 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

@@ -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

Comments
 (0)