Skip to content

Commit

Permalink
Merge branch 'main' into numpy-docstring-timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
tuhinsharma121 authored May 5, 2024
2 parents c5c24bd + eadc129 commit 0647eac
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 5 deletions.
3 changes: 0 additions & 3 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Interval PR02" \
-i "pandas.Interval.closed SA01" \
-i "pandas.Interval.left SA01" \
-i "pandas.Interval.mid SA01" \
-i "pandas.Interval.right SA01" \
-i "pandas.IntervalIndex.closed SA01" \
-i "pandas.IntervalIndex.contains RT03" \
Expand Down Expand Up @@ -207,9 +206,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Series.list.flatten SA01" \
-i "pandas.Series.list.len SA01" \
-i "pandas.Series.lt PR07,SA01" \
-i "pandas.Series.max RT03" \
-i "pandas.Series.mean RT03,SA01" \
-i "pandas.Series.median RT03,SA01" \
-i "pandas.Series.min RT03" \
-i "pandas.Series.mod PR07" \
-i "pandas.Series.mode SA01" \
Expand Down
6 changes: 6 additions & 0 deletions pandas/_libs/interval.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ cdef class IntervalMixin:
"""
Return the midpoint of the Interval.
See Also
--------
Interval.left : Return the left bound for the interval.
Interval.right : Return the right bound for the interval.
Interval.length : Return the length of the interval.
Examples
--------
>>> iv = pd.Interval(0, 5)
Expand Down
130 changes: 128 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -6157,14 +6157,72 @@ def min(
)

@deprecate_nonkeyword_arguments(version="3.0", allowed_args=["self"], name="max")
@doc(make_doc("max", ndim=1))
def max(
self,
axis: Axis | None = 0,
skipna: bool = True,
numeric_only: bool = False,
**kwargs,
):
"""
Return the maximum of the values over the requested axis.
If you want the *index* of the maximum, use ``idxmax``.
This is the equivalent of the ``numpy.ndarray`` method ``argmax``.
Parameters
----------
axis : {index (0)}
Axis for the function to be applied on.
For `Series` this parameter is unused and defaults to 0.
For DataFrames, specifying ``axis=None`` will apply the aggregation
across both axes.
.. versionadded:: 2.0.0
skipna : bool, default True
Exclude NA/null values when computing the result.
numeric_only : bool, default False
Include only float, int, boolean columns.
**kwargs
Additional keyword arguments to be passed to the function.
Returns
-------
scalar or Series (if level specified)
The maximum of the values in the Series.
See Also
--------
numpy.max : Equivalent numpy function for arrays.
Series.min : Return the minimum.
Series.max : Return the maximum.
Series.idxmin : Return the index of the minimum.
Series.idxmax : Return the index of the maximum.
DataFrame.min : Return the minimum over the requested axis.
DataFrame.max : Return the maximum over the requested axis.
DataFrame.idxmin : Return the index of the minimum over the requested axis.
DataFrame.idxmax : Return the index of the maximum over the requested axis.
Examples
--------
>>> idx = pd.MultiIndex.from_arrays(
... [["warm", "warm", "cold", "cold"], ["dog", "falcon", "fish", "spider"]],
... names=["blooded", "animal"],
... )
>>> s = pd.Series([4, 2, 0, 8], name="legs", index=idx)
>>> s
blooded animal
warm dog 4
falcon 2
cold fish 0
spider 8
Name: legs, dtype: int64
>>> s.max()
8
"""
return NDFrame.max(
self, axis=axis, skipna=skipna, numeric_only=numeric_only, **kwargs
)
Expand Down Expand Up @@ -6221,14 +6279,82 @@ def mean(
)

@deprecate_nonkeyword_arguments(version="3.0", allowed_args=["self"], name="median")
@doc(make_doc("median", ndim=1))
def median(
self,
axis: Axis | None = 0,
skipna: bool = True,
numeric_only: bool = False,
**kwargs,
) -> Any:
"""
Return the median of the values over the requested axis.
Parameters
----------
axis : {index (0)}
Axis for the function to be applied on.
For `Series` this parameter is unused and defaults to 0.
For DataFrames, specifying ``axis=None`` will apply the aggregation
across both axes.
.. versionadded:: 2.0.0
skipna : bool, default True
Exclude NA/null values when computing the result.
numeric_only : bool, default False
Include only float, int, boolean columns.
**kwargs
Additional keyword arguments to be passed to the function.
Returns
-------
scalar or Series (if level specified)
Median of the values for the requested axis.
See Also
--------
numpy.median : Equivalent numpy function for computing median.
Series.sum : Sum of the values.
Series.median : Median of the values.
Series.std : Standard deviation of the values.
Series.var : Variance of the values.
Series.min : Minimum value.
Series.max : Maximum value.
Examples
--------
>>> s = pd.Series([1, 2, 3])
>>> s.median()
2.0
With a DataFrame
>>> df = pd.DataFrame({"a": [1, 2], "b": [2, 3]}, index=["tiger", "zebra"])
>>> df
a b
tiger 1 2
zebra 2 3
>>> df.median()
a 1.5
b 2.5
dtype: float64
Using axis=1
>>> df.median(axis=1)
tiger 1.5
zebra 2.5
dtype: float64
In this case, `numeric_only` should be set to `True`
to avoid getting an error.
>>> df = pd.DataFrame({"a": [1, 2], "b": ["T", "Z"]}, index=["tiger", "zebra"])
>>> df.median(numeric_only=True)
a 1.5
dtype: float64
"""
return NDFrame.median(
self, axis=axis, skipna=skipna, numeric_only=numeric_only, **kwargs
)
Expand Down

0 comments on commit 0647eac

Please sign in to comment.