Skip to content

Remove limit, fill_axis, broadcast_axis and method parameters from align #57344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Removal of prior version deprecations/changes
- Removed ``axis`` argument from :meth:`DataFrame.groupby`, :meth:`Series.groupby`, :meth:`DataFrame.rolling`, :meth:`Series.rolling`, :meth:`DataFrame.resample`, and :meth:`Series.resample` (:issue:`51203`)
- Removed ``axis`` argument from all groupby operations (:issue:`50405`)
- Removed ``convert_dtype`` from :meth:`Series.apply` (:issue:`52257`)
- Removed ``method``, ``limit`` ``fill_axis`` and ``broadcast_axis`` keywords from :meth:`DataFrame.align` (:issue:`51968`)
- Removed ``pandas.api.types.is_interval`` and ``pandas.api.types.is_period``, use ``isinstance(obj, pd.Interval)`` and ``isinstance(obj, pd.Period)`` instead (:issue:`55264`)
- Removed ``pandas.io.sql.execute`` (:issue:`50185`)
- Removed ``pandas.value_counts``, use :meth:`Series.value_counts` instead (:issue:`53493`)
Expand Down
147 changes: 4 additions & 143 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9540,10 +9540,6 @@ def align(
level: Level | None = None,
copy: bool | None = None,
fill_value: Hashable | None = None,
method: FillnaOptions | None | lib.NoDefault = lib.no_default,
limit: int | None | lib.NoDefault = lib.no_default,
fill_axis: Axis | lib.NoDefault = lib.no_default,
broadcast_axis: Axis | None | lib.NoDefault = lib.no_default,
) -> tuple[Self, NDFrameT]:
"""
Align two objects on their axes with the specified join method.
Expand Down Expand Up @@ -9585,34 +9581,6 @@ def align(
fill_value : scalar, default np.nan
Value to use for missing values. Defaults to NaN, but can be any
"compatible" value.
method : {{'backfill', 'bfill', 'pad', 'ffill', None}}, default None
Method to use for filling holes in reindexed Series:

- pad / ffill: propagate last valid observation forward to next valid.
- backfill / bfill: use NEXT valid observation to fill gap.

.. deprecated:: 2.1

limit : int, default None
If method is specified, this is the maximum number of consecutive
NaN values to forward/backward fill. In other words, if there is
a gap with more than this number of consecutive NaNs, it will only
be partially filled. If method is not specified, this is the
maximum number of entries along the entire axis where NaNs will be
filled. Must be greater than 0 if not None.

.. deprecated:: 2.1

fill_axis : {axes_single_arg}, default 0
Filling axis, method and limit.

.. deprecated:: 2.1

broadcast_axis : {axes_single_arg}, default None
Broadcast values along this axis, if aligning two objects of
different dimensions.

.. deprecated:: 2.1

Returns
-------
Expand Down Expand Up @@ -9684,92 +9652,6 @@ def align(
3 60.0 70.0 80.0 90.0 NaN
4 600.0 700.0 800.0 900.0 NaN
"""
if (
method is not lib.no_default
or limit is not lib.no_default
or fill_axis is not lib.no_default
):
# GH#51856
warnings.warn(
"The 'method', 'limit', and 'fill_axis' keywords in "
f"{type(self).__name__}.align are deprecated and will be removed "
"in a future version. Call fillna directly on the returned objects "
"instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
if fill_axis is lib.no_default:
fill_axis = 0
if method is lib.no_default:
method = None
if limit is lib.no_default:
limit = None

if method is not None:
method = clean_fill_method(method)

if broadcast_axis is not lib.no_default:
# GH#51856
# TODO(3.0): enforcing this deprecation will close GH#13194
msg = (
f"The 'broadcast_axis' keyword in {type(self).__name__}.align is "
"deprecated and will be removed in a future version."
)
if broadcast_axis is not None:
if self.ndim == 1 and other.ndim == 2:
msg += (
" Use left = DataFrame({col: left for col in right.columns}, "
"index=right.index) before calling `left.align(right)` instead."
)
elif self.ndim == 2 and other.ndim == 1:
msg += (
" Use right = DataFrame({col: right for col in left.columns}, "
"index=left.index) before calling `left.align(right)` instead"
)
warnings.warn(msg, FutureWarning, stacklevel=find_stack_level())
else:
broadcast_axis = None

if broadcast_axis == 1 and self.ndim != other.ndim:
if isinstance(self, ABCSeries):
# this means other is a DataFrame, and we need to broadcast
# self
cons = self._constructor_expanddim
df = cons(
{c: self for c in other.columns}, **other._construct_axes_dict()
)
# error: Incompatible return value type (got "Tuple[DataFrame,
# DataFrame]", expected "Tuple[Self, NDFrameT]")
return df._align_frame( # type: ignore[return-value]
other, # type: ignore[arg-type]
join=join,
axis=axis,
level=level,
fill_value=fill_value,
method=method,
limit=limit,
fill_axis=fill_axis,
)[:2]
elif isinstance(other, ABCSeries):
# this means self is a DataFrame, and we need to broadcast
# other
cons = other._constructor_expanddim
df = cons(
{c: other for c in self.columns}, **self._construct_axes_dict()
)
# error: Incompatible return value type (got "Tuple[NDFrameT,
# DataFrame]", expected "Tuple[Self, NDFrameT]")
return self._align_frame( # type: ignore[return-value]
df,
join=join,
axis=axis,
level=level,
fill_value=fill_value,
method=method,
limit=limit,
fill_axis=fill_axis,
)[:2]

_right: DataFrame | Series
if axis is not None:
axis = self._get_axis_number(axis)
Expand All @@ -9780,9 +9662,6 @@ def align(
axis=axis,
level=level,
fill_value=fill_value,
method=method,
limit=limit,
fill_axis=fill_axis,
)

elif isinstance(other, ABCSeries):
Expand All @@ -9792,9 +9671,6 @@ def align(
axis=axis,
level=level,
fill_value=fill_value,
method=method,
limit=limit,
fill_axis=fill_axis,
)
else: # pragma: no cover
raise TypeError(f"unsupported type: {type(other)}")
Expand Down Expand Up @@ -9825,9 +9701,6 @@ def _align_frame(
axis: Axis | None = None,
level=None,
fill_value=None,
method=None,
limit: int | None = None,
fill_axis: Axis = 0,
) -> tuple[Self, DataFrame, Index | None]:
# defaults
join_index, join_columns = None, None
Expand Down Expand Up @@ -9864,11 +9737,6 @@ def _align_frame(
fill_value=fill_value,
allow_dups=True,
)

if method is not None:
left = left._pad_or_backfill(method, axis=fill_axis, limit=limit)
right = right._pad_or_backfill(method, axis=fill_axis, limit=limit)

return left, right, join_index

@final
Expand All @@ -9879,9 +9747,6 @@ def _align_series(
axis: Axis | None = None,
level=None,
fill_value=None,
method=None,
limit: int | None = None,
fill_axis: Axis = 0,
) -> tuple[Self, Series, Index | None]:
is_series = isinstance(self, ABCSeries)

Expand Down Expand Up @@ -9933,15 +9798,11 @@ def _align_series(
right = other.reindex(join_index, level=level)

# fill
fill_na = notna(fill_value) or (method is not None)
fill_na = notna(fill_value)
if fill_na:
fill_value, method = validate_fillna_kwargs(fill_value, method)
if method is not None:
left = left._pad_or_backfill(method, limit=limit, axis=fill_axis)
right = right._pad_or_backfill(method, limit=limit)
else:
left = left.fillna(fill_value, limit=limit, axis=fill_axis)
right = right.fillna(fill_value, limit=limit)
fill_value, _ = validate_fillna_kwargs(fill_value, None)
left = left.fillna(fill_value)
right = right.fillna(fill_value)

return left, right, join_index

Expand Down
Loading