Skip to content

DEPR: enforce non-positional, keyword deprecations #49507

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 1 commit into from
Nov 4, 2022
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
4 changes: 4 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ Removal of prior version deprecations/changes
- Removed ``keep_tz`` argument in :meth:`DatetimeIndex.to_series` (:issue:`29731`)
- Remove arguments ``names`` and ``dtype`` from :meth:`Index.copy` and ``levels`` and ``codes`` from :meth:`MultiIndex.copy` (:issue:`35853`, :issue:`36685`)
- Remove argument ``inplace`` from :meth:`MultiIndex.set_levels` and :meth:`MultiIndex.set_codes` (:issue:`35626`)
- Removed arguments ``verbose`` and ``encoding`` from :meth:`DataFrame.to_excel` and :meth:`Series.to_excel` (:issue:`47912`)
- Removed argument ``line_terminator`` from :meth:`DataFrame.to_csv` and :meth:`Series.to_csv`, use ``lineterminator`` instead (:issue:`45302`)
- Removed argument ``inplace`` from :meth:`DataFrame.set_axis` and :meth:`Series.set_axis`, use ``obj = obj.set_axis(..., copy=False)`` instead (:issue:`48130`)
- Disallow passing positional arguments to :meth:`MultiIndex.set_levels` and :meth:`MultiIndex.set_codes` (:issue:`41485`)
- Removed :meth:`MultiIndex.is_lexsorted` and :meth:`MultiIndex.lexsort_depth` (:issue:`38701`)
Expand All @@ -310,6 +312,8 @@ Removal of prior version deprecations/changes
- Remove keywords ``convert_float`` and ``mangle_dupe_cols`` from :func:`read_excel` (:issue:`41176`)
- Removed ``errors`` keyword from :meth:`DataFrame.where`, :meth:`Series.where`, :meth:`DataFrame.mask` and :meth:`Series.mask` (:issue:`47728`)
- Disallow passing non-keyword arguments to :func:`read_excel` except ``io`` and ``sheet_name`` (:issue:`34418`)
- Disallow passing non-keyword arguments to :meth:`DataFrame.drop` and :meth:`Series.drop` except ``labels`` (:issue:`41486`)
- Disallow passing non-keyword arguments to :meth:`DataFrame.fillna` and :meth:`Series.fillna` except ``value`` (:issue:`41485`)
- Disallow passing non-keyword arguments to :meth:`StringMethods.split` and :meth:`StringMethods.rsplit` except for ``pat`` (:issue:`47448`)
- Disallow passing non-keyword arguments to :meth:`DataFrame.set_index` except ``keys`` (:issue:`41495`)
- Disallow passing non-keyword arguments to :meth:`Resampler.interpolate` except ``method`` (:issue:`41699`)
Expand Down
8 changes: 3 additions & 5 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5157,12 +5157,10 @@ def drop(
) -> DataFrame | None:
...

# error: Signature of "drop" incompatible with supertype "NDFrame"
# github.com/python/mypy/issues/12387
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"])
def drop( # type: ignore[override]
def drop(
self,
labels: IndexLabel = None,
*,
axis: Axis = 0,
index: IndexLabel = None,
columns: IndexLabel = None,
Expand Down Expand Up @@ -5532,11 +5530,11 @@ def fillna(
...

# error: Signature of "fillna" incompatible with supertype "NDFrame"
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "value"])
@doc(NDFrame.fillna, **_shared_doc_kwargs)
def fillna( # type: ignore[override]
self,
value: Hashable | Mapping | Series | DataFrame = None,
*,
method: FillnaOptions | None = None,
axis: Axis | None = None,
inplace: bool = False,
Expand Down
24 changes: 1 addition & 23 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@
SettingWithCopyWarning,
)
from pandas.util._decorators import (
deprecate_kwarg,
deprecate_nonkeyword_arguments,
doc,
rewrite_axis_style_signature,
)
Expand Down Expand Up @@ -2131,8 +2129,6 @@ def _repr_data_resource_(self):
# I/O Methods

@final
@deprecate_kwarg(old_arg_name="verbose", new_arg_name=None)
@deprecate_kwarg(old_arg_name="encoding", new_arg_name=None)
@doc(
klass="object",
storage_options=_shared_docs["storage_options"],
Expand All @@ -2152,9 +2148,7 @@ def to_excel(
startcol: int = 0,
engine: str | None = None,
merge_cells: bool_t = True,
encoding: lib.NoDefault = lib.no_default,
inf_rep: str = "inf",
verbose: lib.NoDefault = lib.no_default,
freeze_panes: tuple[int, int] | None = None,
storage_options: StorageOptions = None,
) -> None:
Expand Down Expand Up @@ -2204,24 +2198,9 @@ def to_excel(

merge_cells : bool, default True
Write MultiIndex and Hierarchical Rows as merged cells.
encoding : str, optional
Encoding of the resulting excel file. Only necessary for xlwt,
other writers support unicode natively.

.. deprecated:: 1.5.0

This keyword was not used.

inf_rep : str, default 'inf'
Representation for infinity (there is no native representation for
infinity in Excel).
verbose : bool, default True
Display more information in the error logs.

.. deprecated:: 1.5.0

This keyword was not used.

freeze_panes : tuple of int (length 2), optional
Specifies the one-based bottommost row and rightmost column that
is to be frozen.
Expand Down Expand Up @@ -3470,7 +3449,6 @@ def to_csv(
storage_options=_shared_docs["storage_options"],
compression_options=_shared_docs["compression_options"] % "path_or_buf",
)
@deprecate_kwarg(old_arg_name="line_terminator", new_arg_name="lineterminator")
def to_csv(
self,
path_or_buf: FilePath | WriteBuffer[bytes] | WriteBuffer[str] | None = None,
Expand Down Expand Up @@ -4395,10 +4373,10 @@ def drop(
) -> NDFrameT | None:
...

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"])
def drop(
self: NDFrameT,
labels: IndexLabel = None,
*,
axis: Axis = 0,
index: IndexLabel = None,
columns: IndexLabel = None,
Expand Down
9 changes: 3 additions & 6 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
from pandas.util._decorators import (
Appender,
Substitution,
deprecate_nonkeyword_arguments,
doc,
)
from pandas.util._exceptions import find_stack_level
Expand Down Expand Up @@ -5022,12 +5021,10 @@ def drop(
) -> Series | None:
...

# error: Signature of "drop" incompatible with supertype "NDFrame"
# github.com/python/mypy/issues/12387
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"])
def drop( # type: ignore[override]
def drop(
self,
labels: IndexLabel = None,
*,
axis: Axis = 0,
index: IndexLabel = None,
columns: IndexLabel = None,
Expand Down Expand Up @@ -5171,11 +5168,11 @@ def fillna(
...

# error: Signature of "fillna" incompatible with supertype "NDFrame"
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "value"])
@doc(NDFrame.fillna, **_shared_doc_kwargs)
def fillna( # type: ignore[override]
self,
value: Hashable | Mapping | Series | DataFrame = None,
*,
method: FillnaOptions | None = None,
axis: Axis | None = None,
inplace: bool = False,
Expand Down
12 changes: 0 additions & 12 deletions pandas/tests/frame/methods/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,18 +611,6 @@ def test_fillna_downcast_dict(self):
expected = DataFrame({"col1": [1, 2]})
tm.assert_frame_equal(result, expected)

def test_fillna_pos_args_deprecation(self):
# https://github.com/pandas-dev/pandas/issues/41485
df = DataFrame({"a": [1, 2, 3, np.nan]}, dtype=float)
msg = (
r"In a future version of pandas all arguments of DataFrame.fillna "
r"except for the argument 'value' will be keyword-only"
)
with tm.assert_produces_warning(FutureWarning, match=msg):
result = df.fillna(0, None, None)
expected = DataFrame({"a": [1, 2, 3, 0]}, dtype=float)
tm.assert_frame_equal(result, expected)

def test_fillna_with_columns_and_limit(self):
# GH40989
df = DataFrame(
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/io/formats/test_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,7 @@ def test_to_csv_single_level_multi_index(self, ind, expected, frame_or_series):
# see gh-19589
obj = frame_or_series(pd.Series([1], ind, name="data"))

with tm.assert_produces_warning(FutureWarning, match="lineterminator"):
# GH#9568 standardize on lineterminator matching stdlib
result = obj.to_csv(line_terminator="\n", header=True)
result = obj.to_csv(lineterminator="\n", header=True)
assert result == expected

def test_to_csv_string_array_ascii(self):
Expand Down
13 changes: 0 additions & 13 deletions pandas/tests/series/methods/test_drop.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,6 @@ def test_drop_non_empty_list(data, index, drop_labels):
ser.drop(drop_labels)


def test_drop_pos_args_deprecation():
# https://github.com/pandas-dev/pandas/issues/41485
ser = Series([1, 2, 3])
msg = (
r"In a future version of pandas all arguments of Series\.drop "
r"except for the argument 'labels' will be keyword-only"
)
with tm.assert_produces_warning(FutureWarning, match=msg):
result = ser.drop(1, 0)
expected = Series([1, 3], index=[0, 2])
tm.assert_series_equal(result, expected)


def test_drop_index_ea_dtype(any_numeric_ea_dtype):
# GH#45860
df = Series(100, index=Index([1, 2, 2], dtype=any_numeric_ea_dtype))
Expand Down
12 changes: 0 additions & 12 deletions pandas/tests/series/methods/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,18 +829,6 @@ def test_fillna_datetime64_with_timezone_tzinfo(self):
)
tm.assert_series_equal(result, expected)

def test_fillna_pos_args_deprecation(self):
# https://github.com/pandas-dev/pandas/issues/41485
srs = Series([1, 2, 3, np.nan], dtype=float)
msg = (
r"In a future version of pandas all arguments of Series.fillna "
r"except for the argument 'value' will be keyword-only"
)
with tm.assert_produces_warning(FutureWarning, match=msg):
result = srs.fillna(0, None, None)
expected = Series([1, 2, 3, 0], dtype=float)
tm.assert_series_equal(result, expected)

@pytest.mark.parametrize(
"input, input_fillna, expected_data, expected_categories",
[
Expand Down