Skip to content

Commit 6e96215

Browse files
phoflpmhatre1
authored andcommitted
Remove limit, fill_axis, broadcast_axis and method parameters from align (pandas-dev#57344)
* Remove limit, fill_axis, broadcast_axis and method parameters from align * Fixup
1 parent 2a7b2cf commit 6e96215

File tree

4 files changed

+9
-351
lines changed

4 files changed

+9
-351
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ Removal of prior version deprecations/changes
122122
- 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`)
123123
- Removed ``axis`` argument from all groupby operations (:issue:`50405`)
124124
- Removed ``convert_dtype`` from :meth:`Series.apply` (:issue:`52257`)
125+
- Removed ``method``, ``limit`` ``fill_axis`` and ``broadcast_axis`` keywords from :meth:`DataFrame.align` (:issue:`51968`)
125126
- 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`)
126127
- Removed ``pandas.io.sql.execute`` (:issue:`50185`)
127128
- Removed ``pandas.value_counts``, use :meth:`Series.value_counts` instead (:issue:`53493`)

pandas/core/generic.py

+4-143
Original file line numberDiff line numberDiff line change
@@ -9540,10 +9540,6 @@ def align(
95409540
level: Level | None = None,
95419541
copy: bool | None = None,
95429542
fill_value: Hashable | None = None,
9543-
method: FillnaOptions | None | lib.NoDefault = lib.no_default,
9544-
limit: int | None | lib.NoDefault = lib.no_default,
9545-
fill_axis: Axis | lib.NoDefault = lib.no_default,
9546-
broadcast_axis: Axis | None | lib.NoDefault = lib.no_default,
95479543
) -> tuple[Self, NDFrameT]:
95489544
"""
95499545
Align two objects on their axes with the specified join method.
@@ -9585,34 +9581,6 @@ def align(
95859581
fill_value : scalar, default np.nan
95869582
Value to use for missing values. Defaults to NaN, but can be any
95879583
"compatible" value.
9588-
method : {{'backfill', 'bfill', 'pad', 'ffill', None}}, default None
9589-
Method to use for filling holes in reindexed Series:
9590-
9591-
- pad / ffill: propagate last valid observation forward to next valid.
9592-
- backfill / bfill: use NEXT valid observation to fill gap.
9593-
9594-
.. deprecated:: 2.1
9595-
9596-
limit : int, default None
9597-
If method is specified, this is the maximum number of consecutive
9598-
NaN values to forward/backward fill. In other words, if there is
9599-
a gap with more than this number of consecutive NaNs, it will only
9600-
be partially filled. If method is not specified, this is the
9601-
maximum number of entries along the entire axis where NaNs will be
9602-
filled. Must be greater than 0 if not None.
9603-
9604-
.. deprecated:: 2.1
9605-
9606-
fill_axis : {axes_single_arg}, default 0
9607-
Filling axis, method and limit.
9608-
9609-
.. deprecated:: 2.1
9610-
9611-
broadcast_axis : {axes_single_arg}, default None
9612-
Broadcast values along this axis, if aligning two objects of
9613-
different dimensions.
9614-
9615-
.. deprecated:: 2.1
96169584
96179585
Returns
96189586
-------
@@ -9684,92 +9652,6 @@ def align(
96849652
3 60.0 70.0 80.0 90.0 NaN
96859653
4 600.0 700.0 800.0 900.0 NaN
96869654
"""
9687-
if (
9688-
method is not lib.no_default
9689-
or limit is not lib.no_default
9690-
or fill_axis is not lib.no_default
9691-
):
9692-
# GH#51856
9693-
warnings.warn(
9694-
"The 'method', 'limit', and 'fill_axis' keywords in "
9695-
f"{type(self).__name__}.align are deprecated and will be removed "
9696-
"in a future version. Call fillna directly on the returned objects "
9697-
"instead.",
9698-
FutureWarning,
9699-
stacklevel=find_stack_level(),
9700-
)
9701-
if fill_axis is lib.no_default:
9702-
fill_axis = 0
9703-
if method is lib.no_default:
9704-
method = None
9705-
if limit is lib.no_default:
9706-
limit = None
9707-
9708-
if method is not None:
9709-
method = clean_fill_method(method)
9710-
9711-
if broadcast_axis is not lib.no_default:
9712-
# GH#51856
9713-
# TODO(3.0): enforcing this deprecation will close GH#13194
9714-
msg = (
9715-
f"The 'broadcast_axis' keyword in {type(self).__name__}.align is "
9716-
"deprecated and will be removed in a future version."
9717-
)
9718-
if broadcast_axis is not None:
9719-
if self.ndim == 1 and other.ndim == 2:
9720-
msg += (
9721-
" Use left = DataFrame({col: left for col in right.columns}, "
9722-
"index=right.index) before calling `left.align(right)` instead."
9723-
)
9724-
elif self.ndim == 2 and other.ndim == 1:
9725-
msg += (
9726-
" Use right = DataFrame({col: right for col in left.columns}, "
9727-
"index=left.index) before calling `left.align(right)` instead"
9728-
)
9729-
warnings.warn(msg, FutureWarning, stacklevel=find_stack_level())
9730-
else:
9731-
broadcast_axis = None
9732-
9733-
if broadcast_axis == 1 and self.ndim != other.ndim:
9734-
if isinstance(self, ABCSeries):
9735-
# this means other is a DataFrame, and we need to broadcast
9736-
# self
9737-
cons = self._constructor_expanddim
9738-
df = cons(
9739-
{c: self for c in other.columns}, **other._construct_axes_dict()
9740-
)
9741-
# error: Incompatible return value type (got "Tuple[DataFrame,
9742-
# DataFrame]", expected "Tuple[Self, NDFrameT]")
9743-
return df._align_frame( # type: ignore[return-value]
9744-
other, # type: ignore[arg-type]
9745-
join=join,
9746-
axis=axis,
9747-
level=level,
9748-
fill_value=fill_value,
9749-
method=method,
9750-
limit=limit,
9751-
fill_axis=fill_axis,
9752-
)[:2]
9753-
elif isinstance(other, ABCSeries):
9754-
# this means self is a DataFrame, and we need to broadcast
9755-
# other
9756-
cons = other._constructor_expanddim
9757-
df = cons(
9758-
{c: other for c in self.columns}, **self._construct_axes_dict()
9759-
)
9760-
# error: Incompatible return value type (got "Tuple[NDFrameT,
9761-
# DataFrame]", expected "Tuple[Self, NDFrameT]")
9762-
return self._align_frame( # type: ignore[return-value]
9763-
df,
9764-
join=join,
9765-
axis=axis,
9766-
level=level,
9767-
fill_value=fill_value,
9768-
method=method,
9769-
limit=limit,
9770-
fill_axis=fill_axis,
9771-
)[:2]
9772-
97739655
_right: DataFrame | Series
97749656
if axis is not None:
97759657
axis = self._get_axis_number(axis)
@@ -9780,9 +9662,6 @@ def align(
97809662
axis=axis,
97819663
level=level,
97829664
fill_value=fill_value,
9783-
method=method,
9784-
limit=limit,
9785-
fill_axis=fill_axis,
97869665
)
97879666

97889667
elif isinstance(other, ABCSeries):
@@ -9792,9 +9671,6 @@ def align(
97929671
axis=axis,
97939672
level=level,
97949673
fill_value=fill_value,
9795-
method=method,
9796-
limit=limit,
9797-
fill_axis=fill_axis,
97989674
)
97999675
else: # pragma: no cover
98009676
raise TypeError(f"unsupported type: {type(other)}")
@@ -9825,9 +9701,6 @@ def _align_frame(
98259701
axis: Axis | None = None,
98269702
level=None,
98279703
fill_value=None,
9828-
method=None,
9829-
limit: int | None = None,
9830-
fill_axis: Axis = 0,
98319704
) -> tuple[Self, DataFrame, Index | None]:
98329705
# defaults
98339706
join_index, join_columns = None, None
@@ -9864,11 +9737,6 @@ def _align_frame(
98649737
fill_value=fill_value,
98659738
allow_dups=True,
98669739
)
9867-
9868-
if method is not None:
9869-
left = left._pad_or_backfill(method, axis=fill_axis, limit=limit)
9870-
right = right._pad_or_backfill(method, axis=fill_axis, limit=limit)
9871-
98729740
return left, right, join_index
98739741

98749742
@final
@@ -9879,9 +9747,6 @@ def _align_series(
98799747
axis: Axis | None = None,
98809748
level=None,
98819749
fill_value=None,
9882-
method=None,
9883-
limit: int | None = None,
9884-
fill_axis: Axis = 0,
98859750
) -> tuple[Self, Series, Index | None]:
98869751
is_series = isinstance(self, ABCSeries)
98879752

@@ -9933,15 +9798,11 @@ def _align_series(
99339798
right = other.reindex(join_index, level=level)
99349799

99359800
# fill
9936-
fill_na = notna(fill_value) or (method is not None)
9801+
fill_na = notna(fill_value)
99379802
if fill_na:
9938-
fill_value, method = validate_fillna_kwargs(fill_value, method)
9939-
if method is not None:
9940-
left = left._pad_or_backfill(method, limit=limit, axis=fill_axis)
9941-
right = right._pad_or_backfill(method, limit=limit)
9942-
else:
9943-
left = left.fillna(fill_value, limit=limit, axis=fill_axis)
9944-
right = right.fillna(fill_value, limit=limit)
9803+
fill_value, _ = validate_fillna_kwargs(fill_value, None)
9804+
left = left.fillna(fill_value)
9805+
right = right.fillna(fill_value)
99459806

99469807
return left, right, join_index
99479808

0 commit comments

Comments
 (0)