Skip to content

Commit 0907f2e

Browse files
Merge remote-tracking branch 'upstream/main' into numpy-docstring-int
2 parents 27efe8c + 8cc036c commit 0907f2e

File tree

3 files changed

+165
-10
lines changed

3 files changed

+165
-10
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7575
-i "pandas.DataFrame.median RT03,SA01" \
7676
-i "pandas.DataFrame.min RT03" \
7777
-i "pandas.DataFrame.plot PR02,SA01" \
78-
-i "pandas.DataFrame.prod RT03" \
79-
-i "pandas.DataFrame.product RT03" \
8078
-i "pandas.DataFrame.sem PR01,RT03,SA01" \
81-
-i "pandas.DataFrame.skew RT03,SA01" \
8279
-i "pandas.DataFrame.sparse PR01" \
8380
-i "pandas.DataFrame.std PR01,RT03,SA01" \
8481
-i "pandas.DataFrame.sum RT03" \
@@ -87,13 +84,10 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8784
-i "pandas.DataFrame.var PR01,RT03,SA01" \
8885
-i "pandas.Grouper PR02" \
8986
-i "pandas.Index PR07" \
90-
-i "pandas.Index.get_indexer PR07,SA01" \
9187
-i "pandas.Index.get_indexer_for PR01,SA01" \
92-
-i "pandas.Index.get_indexer_non_unique PR07,SA01" \
9388
-i "pandas.Index.get_loc PR07,RT03,SA01" \
9489
-i "pandas.Index.join PR07,RT03,SA01" \
9590
-i "pandas.Index.names GL08" \
96-
-i "pandas.Index.putmask PR01,RT03" \
9791
-i "pandas.Index.ravel PR01,RT03" \
9892
-i "pandas.Index.str PR01,SA01" \
9993
-i "pandas.Interval PR02" \
@@ -105,7 +99,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
10599
-i "pandas.IntervalDtype.subtype SA01" \
106100
-i "pandas.IntervalIndex.closed SA01" \
107101
-i "pandas.IntervalIndex.contains RT03" \
108-
-i "pandas.IntervalIndex.get_indexer PR07,SA01" \
109102
-i "pandas.IntervalIndex.get_loc PR07,RT03,SA01" \
110103
-i "pandas.IntervalIndex.is_non_overlapping_monotonic SA01" \
111104
-i "pandas.IntervalIndex.left GL08" \
@@ -119,7 +112,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
119112
-i "pandas.MultiIndex.copy PR07,RT03,SA01" \
120113
-i "pandas.MultiIndex.drop PR07,RT03,SA01" \
121114
-i "pandas.MultiIndex.dtypes SA01" \
122-
-i "pandas.MultiIndex.get_indexer PR07,SA01" \
123115
-i "pandas.MultiIndex.get_level_values SA01" \
124116
-i "pandas.MultiIndex.get_loc PR07" \
125117
-i "pandas.MultiIndex.get_loc_level PR07" \

pandas/core/frame.py

Lines changed: 141 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11730,7 +11730,6 @@ def sum(
1173011730
return result
1173111731

1173211732
@deprecate_nonkeyword_arguments(version="3.0", allowed_args=["self"], name="prod")
11733-
@doc(make_doc("prod", ndim=2))
1173411733
def prod(
1173511734
self,
1173611735
axis: Axis | None = 0,
@@ -11739,6 +11738,73 @@ def prod(
1173911738
min_count: int = 0,
1174011739
**kwargs,
1174111740
) -> Series:
11741+
"""
11742+
Return the product of the values over the requested axis.
11743+
11744+
Parameters
11745+
----------
11746+
axis : {index (0), columns (1)}
11747+
Axis for the function to be applied on.
11748+
For `Series` this parameter is unused and defaults to 0.
11749+
11750+
.. warning::
11751+
11752+
The behavior of DataFrame.prod with ``axis=None`` is deprecated,
11753+
in a future version this will reduce over both axes and return a scalar
11754+
To retain the old behavior, pass axis=0 (or do not pass axis).
11755+
11756+
.. versionadded:: 2.0.0
11757+
11758+
skipna : bool, default True
11759+
Exclude NA/null values when computing the result.
11760+
numeric_only : bool, default False
11761+
Include only float, int, boolean columns. Not implemented for Series.
11762+
11763+
min_count : int, default 0
11764+
The required number of valid values to perform the operation. If fewer than
11765+
``min_count`` non-NA values are present the result will be NA.
11766+
**kwargs
11767+
Additional keyword arguments to be passed to the function.
11768+
11769+
Returns
11770+
-------
11771+
Series or scalar
11772+
The product of the values over the requested axis.
11773+
11774+
See Also
11775+
--------
11776+
Series.sum : Return the sum.
11777+
Series.min : Return the minimum.
11778+
Series.max : Return the maximum.
11779+
Series.idxmin : Return the index of the minimum.
11780+
Series.idxmax : Return the index of the maximum.
11781+
DataFrame.sum : Return the sum over the requested axis.
11782+
DataFrame.min : Return the minimum over the requested axis.
11783+
DataFrame.max : Return the maximum over the requested axis.
11784+
DataFrame.idxmin : Return the index of the minimum over the requested axis.
11785+
DataFrame.idxmax : Return the index of the maximum over the requested axis.
11786+
11787+
Examples
11788+
--------
11789+
By default, the product of an empty or all-NA Series is ``1``
11790+
11791+
>>> pd.Series([], dtype="float64").prod()
11792+
1.0
11793+
11794+
This can be controlled with the ``min_count`` parameter
11795+
11796+
>>> pd.Series([], dtype="float64").prod(min_count=1)
11797+
nan
11798+
11799+
Thanks to the ``skipna`` parameter, ``min_count`` handles all-NA and
11800+
empty series identically.
11801+
11802+
>>> pd.Series([np.nan]).prod()
11803+
1.0
11804+
11805+
>>> pd.Series([np.nan]).prod(min_count=1)
11806+
nan
11807+
"""
1174211808
result = super().prod(
1174311809
axis=axis,
1174411810
skipna=skipna,
@@ -12029,14 +12095,87 @@ def skew(
1202912095
) -> Series | Any: ...
1203012096

1203112097
@deprecate_nonkeyword_arguments(version="3.0", allowed_args=["self"], name="skew")
12032-
@doc(make_doc("skew", ndim=2))
1203312098
def skew(
1203412099
self,
1203512100
axis: Axis | None = 0,
1203612101
skipna: bool = True,
1203712102
numeric_only: bool = False,
1203812103
**kwargs,
1203912104
) -> Series | Any:
12105+
"""
12106+
Return unbiased skew over requested axis.
12107+
12108+
Normalized by N-1.
12109+
12110+
Parameters
12111+
----------
12112+
axis : {index (0), columns (1)}
12113+
Axis for the function to be applied on.
12114+
For `Series` this parameter is unused and defaults to 0.
12115+
12116+
For DataFrames, specifying ``axis=None`` will apply the aggregation
12117+
across both axes.
12118+
12119+
.. versionadded:: 2.0.0
12120+
12121+
skipna : bool, default True
12122+
Exclude NA/null values when computing the result.
12123+
numeric_only : bool, default False
12124+
Include only float, int, boolean columns.
12125+
12126+
**kwargs
12127+
Additional keyword arguments to be passed to the function.
12128+
12129+
Returns
12130+
-------
12131+
Series or scalar
12132+
Unbiased skew over requested axis.
12133+
12134+
See Also
12135+
--------
12136+
Dataframe.kurt : Returns unbiased kurtosis over requested axis.
12137+
12138+
Examples
12139+
--------
12140+
>>> s = pd.Series([1, 2, 3])
12141+
>>> s.skew()
12142+
0.0
12143+
12144+
With a DataFrame
12145+
12146+
>>> df = pd.DataFrame(
12147+
... {"a": [1, 2, 3], "b": [2, 3, 4], "c": [1, 3, 5]},
12148+
... index=["tiger", "zebra", "cow"],
12149+
... )
12150+
>>> df
12151+
a b c
12152+
tiger 1 2 1
12153+
zebra 2 3 3
12154+
cow 3 4 5
12155+
>>> df.skew()
12156+
a 0.0
12157+
b 0.0
12158+
c 0.0
12159+
dtype: float64
12160+
12161+
Using axis=1
12162+
12163+
>>> df.skew(axis=1)
12164+
tiger 1.732051
12165+
zebra -1.732051
12166+
cow 0.000000
12167+
dtype: float64
12168+
12169+
In this case, `numeric_only` should be set to `True` to avoid
12170+
getting an error.
12171+
12172+
>>> df = pd.DataFrame(
12173+
... {"a": [1, 2, 3], "b": ["T", "Z", "X"]}, index=["tiger", "zebra", "cow"]
12174+
... )
12175+
>>> df.skew(numeric_only=True)
12176+
a 0.0
12177+
dtype: float64
12178+
"""
1204012179
result = super().skew(
1204112180
axis=axis, skipna=skipna, numeric_only=numeric_only, **kwargs
1204212181
)

pandas/core/indexes/base.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3543,6 +3543,7 @@ def get_indexer(
35433543
Parameters
35443544
----------
35453545
target : Index
3546+
An iterable containing the values to be used for computing indexer.
35463547
method : {None, 'pad'/'ffill', 'backfill'/'bfill', 'nearest'}, optional
35473548
* default: exact matches only.
35483549
* pad / ffill: find the PREVIOUS index value if no exact match.
@@ -3570,6 +3571,12 @@ def get_indexer(
35703571
positions matches the corresponding target values. Missing values
35713572
in the target are marked by -1.
35723573
3574+
See Also
3575+
--------
3576+
Index.get_indexer_for : Returns an indexer even when non-unique.
3577+
Index.get_non_unique : Returns indexer and masks for new index given
3578+
the current index.
3579+
35733580
Notes
35743581
-----
35753582
Returns -1 for unmatched values, for further explanation see the
@@ -5253,9 +5260,19 @@ def putmask(self, mask, value) -> Index:
52535260
"""
52545261
Return a new Index of the values set with the mask.
52555262
5263+
Parameters
5264+
----------
5265+
mask : np.ndarray[bool]
5266+
Array of booleans denoting where values in the original
5267+
data are not ``NA``.
5268+
value : scalar
5269+
Scalar value to use to fill holes (e.g. 0).
5270+
This value cannot be a list-likes.
5271+
52565272
Returns
52575273
-------
52585274
Index
5275+
A new Index of the values set with the mask.
52595276
52605277
See Also
52615278
--------
@@ -5843,6 +5860,7 @@ def _should_fallback_to_positional(self) -> bool:
58435860
Parameters
58445861
----------
58455862
target : %(target_klass)s
5863+
An iterable containing the values to be used for computing indexer.
58465864
58475865
Returns
58485866
-------
@@ -5854,6 +5872,12 @@ def _should_fallback_to_positional(self) -> bool:
58545872
An indexer into the target of the values not found.
58555873
These correspond to the -1 in the indexer array.
58565874
5875+
See Also
5876+
--------
5877+
Index.get_indexer : Computes indexer and mask for new index given
5878+
the current index.
5879+
Index.get_indexer_for : Returns an indexer even when non-unique.
5880+
58575881
Examples
58585882
--------
58595883
>>> index = pd.Index(['c', 'b', 'a', 'b', 'b'])

0 commit comments

Comments
 (0)