Skip to content

Commit eadc129

Browse files
DOC: Enforce Numpy Docstring Validation for pandas.Series.median (#58575)
* DOC: add RT03,SA01 for pandas.Series.median * DOC: remove RT03,SA01 for pandas.Series.median
1 parent 006ed98 commit eadc129

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
207207
-i "pandas.Series.list.len SA01" \
208208
-i "pandas.Series.lt PR07,SA01" \
209209
-i "pandas.Series.mean RT03,SA01" \
210-
-i "pandas.Series.median RT03,SA01" \
211210
-i "pandas.Series.min RT03" \
212211
-i "pandas.Series.mod PR07" \
213212
-i "pandas.Series.mode SA01" \

pandas/core/series.py

+69-1
Original file line numberDiff line numberDiff line change
@@ -6279,14 +6279,82 @@ def mean(
62796279
)
62806280

62816281
@deprecate_nonkeyword_arguments(version="3.0", allowed_args=["self"], name="median")
6282-
@doc(make_doc("median", ndim=1))
62836282
def median(
62846283
self,
62856284
axis: Axis | None = 0,
62866285
skipna: bool = True,
62876286
numeric_only: bool = False,
62886287
**kwargs,
62896288
) -> Any:
6289+
"""
6290+
Return the median of the values over the requested axis.
6291+
6292+
Parameters
6293+
----------
6294+
axis : {index (0)}
6295+
Axis for the function to be applied on.
6296+
For `Series` this parameter is unused and defaults to 0.
6297+
6298+
For DataFrames, specifying ``axis=None`` will apply the aggregation
6299+
across both axes.
6300+
6301+
.. versionadded:: 2.0.0
6302+
6303+
skipna : bool, default True
6304+
Exclude NA/null values when computing the result.
6305+
numeric_only : bool, default False
6306+
Include only float, int, boolean columns.
6307+
**kwargs
6308+
Additional keyword arguments to be passed to the function.
6309+
6310+
Returns
6311+
-------
6312+
scalar or Series (if level specified)
6313+
Median of the values for the requested axis.
6314+
6315+
See Also
6316+
--------
6317+
numpy.median : Equivalent numpy function for computing median.
6318+
Series.sum : Sum of the values.
6319+
Series.median : Median of the values.
6320+
Series.std : Standard deviation of the values.
6321+
Series.var : Variance of the values.
6322+
Series.min : Minimum value.
6323+
Series.max : Maximum value.
6324+
6325+
Examples
6326+
--------
6327+
>>> s = pd.Series([1, 2, 3])
6328+
>>> s.median()
6329+
2.0
6330+
6331+
With a DataFrame
6332+
6333+
>>> df = pd.DataFrame({"a": [1, 2], "b": [2, 3]}, index=["tiger", "zebra"])
6334+
>>> df
6335+
a b
6336+
tiger 1 2
6337+
zebra 2 3
6338+
>>> df.median()
6339+
a 1.5
6340+
b 2.5
6341+
dtype: float64
6342+
6343+
Using axis=1
6344+
6345+
>>> df.median(axis=1)
6346+
tiger 1.5
6347+
zebra 2.5
6348+
dtype: float64
6349+
6350+
In this case, `numeric_only` should be set to `True`
6351+
to avoid getting an error.
6352+
6353+
>>> df = pd.DataFrame({"a": [1, 2], "b": ["T", "Z"]}, index=["tiger", "zebra"])
6354+
>>> df.median(numeric_only=True)
6355+
a 1.5
6356+
dtype: float64
6357+
"""
62906358
return NDFrame.median(
62916359
self, axis=axis, skipna=skipna, numeric_only=numeric_only, **kwargs
62926360
)

0 commit comments

Comments
 (0)