Skip to content

Commit

Permalink
use fill_method=None
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie-XIAO committed Oct 15, 2023
1 parent 7991ac6 commit 096bc78
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 44 deletions.
39 changes: 17 additions & 22 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11822,22 +11822,22 @@ def pct_change(
# `fill_method=None` that does not fill missing values
if fill_method not in (lib.no_default, None) and limit is not lib.no_default:
# `fill_method` in FillnaOptions and `limit` is specified
fill_type = "bfill" if fill_method in ("backfill", "bfill") else "ffill"
warnings.warn(
f"fill_method={fill_method} and the limit keyword in "
f"{type(self).__name__}.pct_change are deprecated and will be removed "
"in a future version. Call "
f"{'bfill' if fill_method in ('backfill', 'bfill') else 'ffill'}"
f"(limit={limit}) before calling pct_change instead.",
f"in a future version. Use obj.{fill_type}(limit={limit}).pct_change"
"(fill_method=None) instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
elif fill_method not in (lib.no_default, None):
# `fill_method` in FillnaOptions and `limit` is not specified
fill_type = "bfill" if fill_method in ("backfill", "bfill") else "ffill"
warnings.warn(
f"fill_method={fill_method} in {type(self).__name__}.pct_change is "
"deprecated and will be removed in a future version. Call "
f"{'bfill' if fill_method in ('backfill', 'bfill') else 'ffill'} "
"before calling pct_change instead.",
"deprecated and will be removed in a future version. Use "
f"obj.{fill_type}().pct_change(fill_method=None) instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
Expand All @@ -11863,29 +11863,24 @@ def pct_change(
warnings.warn(
"The default fill_method='pad' and the limit keyword in "
f"{type(self).__name__}.pct_change are deprecated and will be removed "
f"in a future version. Call ffill(limit={limit}) before calling "
"pct_change to retain the current behavior and silence this warning.",
f"in a future version. Use obj.ffill(limit={limit}).pct_change"
"(fill_method=None) to retain the current behavior and silence this "
"warning.",
FutureWarning,
stacklevel=find_stack_level(),
)
fill_method = "pad"
else:
# `fill_method` and `limit` are both not specified
# GH#54981: avoid unnecessary FutureWarning
cols = self.items() if self.ndim == 2 else [(None, self)]
for _, col in cols:
mask = col.isna().values
mask = mask[np.argmax(~mask) :]
if mask.any():
warnings.warn(
"The default fill_method='pad' in "
f"{type(self).__name__}.pct_change is deprecated and will be "
"removed in a future version. Call ffill before calling "
"pct_change to retain current behavior and silence this "
"warning.",
FutureWarning,
stacklevel=find_stack_level(),
)
warnings.warn(
"The default fill_method='pad' and the limit keyword in "
f"{type(self).__name__}.pct_change are deprecated and will be removed "
f"in a future version. Use obj.ffill().pct_change(fill_method=None) "
"to retain the current behavior and silence this warning.",
FutureWarning,
stacklevel=find_stack_level(),
)
fill_method, limit = "pad", None

axis = self._get_axis_number(kwargs.pop("axis", "index"))
Expand Down
39 changes: 17 additions & 22 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -5341,22 +5341,22 @@ def pct_change(
# `fill_method=None` that does not fill missing values
if fill_method not in (lib.no_default, None) and limit is not lib.no_default:
# `fill_method` in FillnaOptions and `limit` is specified
fill_type = "bfill" if fill_method in ("backfill", "bfill") else "ffill"
warnings.warn(
f"fill_method={fill_method} and the limit keyword in "
f"{type(self).__name__}.pct_change are deprecated and will be removed "
"in a future version. Call "
f"{'bfill' if fill_method in ('backfill', 'bfill') else 'ffill'}"
f"(limit={limit}) before calling pct_change instead.",
f"in a future version. Use obj.{fill_type}(limit={limit}).pct_change"
"(fill_method=None) instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
elif fill_method not in (lib.no_default, None):
# `fill_method` in FillnaOptions and `limit` is not specified
fill_type = "bfill" if fill_method in ("backfill", "bfill") else "ffill"
warnings.warn(
f"fill_method={fill_method} in {type(self).__name__}.pct_change is "
"deprecated and will be removed in a future version. Call "
f"{'bfill' if fill_method in ('backfill', 'bfill') else 'ffill'} "
"before calling pct_change instead.",
"deprecated and will be removed in a future version. Use "
f"obj.{fill_type}().pct_change(fill_method=None) instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
Expand All @@ -5382,29 +5382,24 @@ def pct_change(
warnings.warn(
"The default fill_method='pad' and the limit keyword in "
f"{type(self).__name__}.pct_change are deprecated and will be removed "
f"in a future version. Call ffill(limit={limit}) before calling "
"pct_change to retain the current behavior and silence this warning.",
f"in a future version. Use obj.ffill(limit={limit}).pct_change"
"(fill_method=None) to retain the current behavior and silence this "
"warning.",
FutureWarning,
stacklevel=find_stack_level(),
)
fill_method = "pad"
else:
# `fill_method` and `limit` are both not specified
# GH#54981: avoid unnecessary FutureWarning
cols = self.items() if self.ndim == 2 else [(None, self)]
for _, col in cols:
mask = col.isna().values
mask = mask[np.argmax(~mask) :]
if mask.any():
warnings.warn(
"The default fill_method='pad' in "
f"{type(self).__name__}.pct_change is deprecated and will be "
"removed in a future version. Call ffill before calling "
"pct_change to retain current behavior and silence this "
"warning.",
FutureWarning,
stacklevel=find_stack_level(),
)
warnings.warn(
"The default fill_method='pad' and the limit keyword in "
f"{type(self).__name__}.pct_change are deprecated and will be removed "
f"in a future version. Use obj.ffill().pct_change(fill_method=None) "
"to retain the current behavior and silence this warning.",
FutureWarning,
stacklevel=find_stack_level(),
)
fill_method, limit = "pad", None

if axis is not lib.no_default:
Expand Down

0 comments on commit 096bc78

Please sign in to comment.