Skip to content

Commit 4c9246a

Browse files
authored
Merge branch 'main' into bugfix-spss-kwargs
2 parents ab6e232 + 7368686 commit 4c9246a

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

doc/source/whatsnew/v2.2.1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ including other versions of pandas.
1414
Fixed regressions
1515
~~~~~~~~~~~~~~~~~
1616
- Fixed regression in :func:`merge_ordered` raising ``TypeError`` for ``fill_method="ffill"`` and ``how="left"`` (:issue:`57010`)
17+
- Fixed regression in :meth:`Series.pct_change` raising a ``ValueError`` for an empty :class:`Series` (:issue:`57056`)
1718

1819
.. ---------------------------------------------------------------------------
1920
.. _whatsnew_221.bug_fixes:

pandas/compat/numpy/function.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def validate_argmax_with_skipna(skipna: bool | ndarray | None, args, kwargs) ->
138138
ARGSORT_DEFAULTS["kind"] = "quicksort"
139139
ARGSORT_DEFAULTS["order"] = None
140140
ARGSORT_DEFAULTS["kind"] = None
141+
ARGSORT_DEFAULTS["stable"] = None
141142

142143

143144
validate_argsort = CompatValidator(
@@ -149,6 +150,7 @@ def validate_argmax_with_skipna(skipna: bool | ndarray | None, args, kwargs) ->
149150
ARGSORT_DEFAULTS_KIND: dict[str, int | None] = {}
150151
ARGSORT_DEFAULTS_KIND["axis"] = -1
151152
ARGSORT_DEFAULTS_KIND["order"] = None
153+
ARGSORT_DEFAULTS_KIND["stable"] = None
152154
validate_argsort_kind = CompatValidator(
153155
ARGSORT_DEFAULTS_KIND, fname="argsort", max_fname_arg_count=0, method="both"
154156
)

pandas/core/generic.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12148,19 +12148,20 @@ def pct_change(
1214812148
if limit is lib.no_default:
1214912149
cols = self.items() if self.ndim == 2 else [(None, self)]
1215012150
for _, col in cols:
12151-
mask = col.isna().values
12152-
mask = mask[np.argmax(~mask) :]
12153-
if mask.any():
12154-
warnings.warn(
12155-
"The default fill_method='pad' in "
12156-
f"{type(self).__name__}.pct_change is deprecated and will "
12157-
"be removed in a future version. Either fill in any "
12158-
"non-leading NA values prior to calling pct_change or "
12159-
"specify 'fill_method=None' to not fill NA values.",
12160-
FutureWarning,
12161-
stacklevel=find_stack_level(),
12162-
)
12163-
break
12151+
if len(col) > 0:
12152+
mask = col.isna().values
12153+
mask = mask[np.argmax(~mask) :]
12154+
if mask.any():
12155+
warnings.warn(
12156+
"The default fill_method='pad' in "
12157+
f"{type(self).__name__}.pct_change is deprecated and "
12158+
"will be removed in a future version. Either fill in "
12159+
"any non-leading NA values prior to calling pct_change "
12160+
"or specify 'fill_method=None' to not fill NA values.",
12161+
FutureWarning,
12162+
stacklevel=find_stack_level(),
12163+
)
12164+
break
1216412165
fill_method = "pad"
1216512166
if limit is lib.no_default:
1216612167
limit = None

pandas/core/indexes/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ def __array_ufunc__(self, ufunc: np.ufunc, method: str_t, *inputs, **kwargs):
958958
return self.__array_wrap__(result)
959959

960960
@final
961-
def __array_wrap__(self, result, context=None):
961+
def __array_wrap__(self, result, context=None, return_scalar=False):
962962
"""
963963
Gets called after a ufunc and other functions e.g. np.split.
964964
"""

pandas/core/series.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4070,6 +4070,7 @@ def argsort(
40704070
axis: Axis = 0,
40714071
kind: SortKind = "quicksort",
40724072
order: None = None,
4073+
stable: None = None,
40734074
) -> Series:
40744075
"""
40754076
Return the integer indices that would sort the Series values.
@@ -4086,6 +4087,8 @@ def argsort(
40864087
information. 'mergesort' and 'stable' are the only stable algorithms.
40874088
order : None
40884089
Has no effect but is accepted for compatibility with numpy.
4090+
stable : None
4091+
Has no effect but is accepted for compatibility with numpy.
40894092
40904093
Returns
40914094
-------

pandas/tests/series/methods/test_pct_change.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,11 @@ def test_pct_change_no_warning_na_beginning():
118118
result = ser.pct_change()
119119
expected = Series([np.nan, np.nan, np.nan, 1, 0.5])
120120
tm.assert_series_equal(result, expected)
121+
122+
123+
def test_pct_change_empty():
124+
# GH 57056
125+
ser = Series([], dtype="float64")
126+
expected = ser.copy()
127+
result = ser.pct_change(periods=0)
128+
tm.assert_series_equal(expected, result)

0 commit comments

Comments
 (0)