diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 8359faa8a5d7ad..9b449917ff9780 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -7113,6 +7113,10 @@ def quantile(self, q=0.5, axis=0, numeric_only=True, a b 0.1 1.3 3.7 0.5 2.5 55.0 + + See Also + -------- + pandas.core.window.Rolling.quantile """ self._check_percentile(q) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index f9b0e6858c2772..a52f04bf3ff800 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -256,7 +256,7 @@ def test_mode_numerical(self, dropna, expected1, expected2, expected3): @pytest.mark.parametrize('dropna, expected1, expected2, expected3', [ (True, ['b'], ['bar'], ['nan']), - (False, ['b'], ['bar', np.nan], ['nan']) + (False, ['b'], [np.nan], ['nan']) ]) def test_mode_str_obj(self, dropna, expected1, expected2, expected3): # Test string and object types. @@ -266,7 +266,7 @@ def test_mode_str_obj(self, dropna, expected1, expected2, expected3): expected1 = Series(expected1, dtype='c') tm.assert_series_equal(s.mode(dropna), expected1) - data = ['foo', 'bar', 'bar', np.nan, np.nan] + data = ['foo', 'bar', 'bar', np.nan, np.nan, np.nan] s = Series(data, dtype=object) expected2 = Series(expected2, dtype=object) @@ -281,22 +281,22 @@ def test_mode_str_obj(self, dropna, expected1, expected2, expected3): @pytest.mark.parametrize('dropna, expected1, expected2', [ (True, ['foo'], ['foo']), - (False, ['foo'], ['foo', np.nan]) + (False, ['foo'], [np.nan]) ]) def test_mode_mixeddtype(self, dropna, expected1, expected2): expected = Series(expected1) s = Series([1, 'foo', 'foo']) tm.assert_series_equal(s.mode(dropna), expected) - expected = Series(expected2) - s = Series([1, 'foo', 'foo', np.nan, np.nan]) + expected = Series(expected2, dtype=object) + s = Series([1, 'foo', 'foo', np.nan, np.nan, np.nan]) result = s.mode(dropna).sort_values().reset_index(drop=True) tm.assert_series_equal(result, expected) @pytest.mark.parametrize('dropna, expected1, expected2', [ (True, ['1900-05-03', '2011-01-03', '2013-01-02'], ['2011-01-03', '2013-01-02']), - (False, [np.nan], ['nan', '2011-01-03', '2013-01-02']), + (False, [np.nan], [np.nan, '2011-01-03', '2013-01-02']), ]) def test_mode_datetime(self, dropna, expected1, expected2): expected1 = Series(expected1, dtype='M8[ns]') @@ -312,7 +312,7 @@ def test_mode_datetime(self, dropna, expected1, expected2): @pytest.mark.parametrize('dropna, expected1, expected2', [ (True, ['-1 days', '0 days', '1 days'], ['2 min', '1 day']), - (False, ['nan'], ['nan', '2 min', '1 day']), + (False, [np.nan], [np.nan, '2 min', '1 day']), ]) def test_mode_timedelta(self, dropna, expected1, expected2): # gh-5986: Test timedelta types. @@ -363,6 +363,21 @@ def test_mode_intoverflow(self, dropna, expected1, expected2): s = Series([1, 2**63], dtype=np.uint64) tm.assert_series_equal(s.mode(dropna), expected2) + @pytest.mark.parametrize('dropna, expected', [ + (False, ['foo', np.nan]), + ]) + def test_mode_sortwarning(self, dropna, expected): + # Check for the warning that is raised when the mode + # results cannot be sorted + + expected = Series(expected) + s = Series([1, 'foo', 'foo', np.nan, np.nan]) + + with tm.assert_produces_warning(UserWarning, check_stacklevel=False): + result = s.mode(dropna).sort_values().reset_index(drop=True) + + tm.assert_series_equal(result, expected) + def test_prod(self): self._check_stat_op('prod', np.prod)