From 0f6592fafadaf60f06c3c7509a6bc02050d5006a Mon Sep 17 00:00:00 2001 From: Thierry Moisan Date: Mon, 26 Nov 2018 19:49:17 -0500 Subject: [PATCH] DOC: fix pandas.DataFrame.quantile docstring and doctests --- ci/code_checks.sh | 2 +- pandas/core/frame.py | 35 +++++++++++++++++------------------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 45cb1708258d7..129742d998f2c 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -147,7 +147,7 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then MSG='Doctests frame.py' ; echo $MSG pytest -q --doctest-modules pandas/core/frame.py \ - -k"-axes -combine -itertuples -join -pivot_table -quantile -query -reindex -reindex_axis -replace -round -set_index -stack" + -k"-axes -combine -itertuples -join -pivot_table -query -reindex -reindex_axis -replace -round -set_index -stack" RET=$(($RET + $?)) ; echo $MSG "DONE" MSG='Doctests series.py' ; echo $MSG diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 592825a7ea63b..958947ef6bfe0 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -7516,15 +7516,13 @@ def quantile(self, q=0.5, axis=0, numeric_only=True, Parameters ---------- q : float or array-like, default 0.5 (50% quantile) - 0 <= q <= 1, the quantile(s) to compute + Value between 0 <= q <= 1, the quantile(s) to compute. axis : {0, 1, 'index', 'columns'} (default 0) - 0 or 'index' for row-wise, 1 or 'columns' for column-wise - numeric_only : boolean, default True + Equals 0 or 'index' for row-wise, 1 or 'columns' for column-wise. + numeric_only : bool, default True If False, the quantile of datetime and timedelta data will be - computed as well + computed as well. interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'} - .. versionadded:: 0.18.0 - This optional parameter specifies the interpolation method to use, when the desired quantile lies between two data points `i` and `j`: @@ -7535,6 +7533,8 @@ def quantile(self, q=0.5, axis=0, numeric_only=True, * nearest: `i` or `j` whichever is nearest. * midpoint: (`i` + `j`) / 2. + .. versionadded:: 0.18.0 + Returns ------- quantiles : Series or DataFrame @@ -7545,15 +7545,19 @@ def quantile(self, q=0.5, axis=0, numeric_only=True, - If ``q`` is a float, a Series will be returned where the index is the columns of self and the values are the quantiles. - Examples + See Also -------- + core.window.Rolling.quantile: Rolling quantile. + numpy.percentile: Numpy function to compute the percentile. + Examples + -------- >>> df = pd.DataFrame(np.array([[1, 1], [2, 10], [3, 100], [4, 100]]), - columns=['a', 'b']) + ... columns=['a', 'b']) >>> df.quantile(.1) a 1.3 b 3.7 - dtype: float64 + Name: 0.1, dtype: float64 >>> df.quantile([.1, .5]) a b 0.1 1.3 3.7 @@ -7563,20 +7567,15 @@ def quantile(self, q=0.5, axis=0, numeric_only=True, datetime and timedelta data. >>> df = pd.DataFrame({'A': [1, 2], - 'B': [pd.Timestamp('2010'), - pd.Timestamp('2011')], - 'C': [pd.Timedelta('1 days'), - pd.Timedelta('2 days')]}) + ... 'B': [pd.Timestamp('2010'), + ... pd.Timestamp('2011')], + ... 'C': [pd.Timedelta('1 days'), + ... pd.Timedelta('2 days')]}) >>> df.quantile(0.5, numeric_only=False) A 1.5 B 2010-07-02 12:00:00 C 1 days 12:00:00 Name: 0.5, dtype: object - - See Also - -------- - pandas.core.window.Rolling.quantile - numpy.percentile """ self._check_percentile(q)