Skip to content
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

DEPR: non-keyword arguments #49359

Merged
merged 2 commits into from
Oct 28, 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
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def setup(self):
self.df = DataFrame(data)

def time_reshape_pivot_time_series(self):
self.df.pivot("date", "variable", "value")
self.df.pivot(index="date", columns="variable", values="value")


class SimpleReshape:
Expand Down
10 changes: 10 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ Removal of prior version deprecations/changes
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)
- Remove keywords ``convert_float`` and ``mangle_dupe_cols`` from :func:`read_excel` (:issue:`41176`)
- Disallow passing non-keyword arguments to :func:`read_excel` except ``io`` and ``sheet_name`` (:issue:`34418`)
- 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`)
- Disallow passing non-keyword arguments to :meth:`DataFrame.reset_index` and :meth:`Series.reset_index` except ``level`` (:issue:`41496`)
- Disallow passing non-keyword arguments to :meth:`DataFrame.dropna` and :meth:`Series.dropna` (:issue:`41504`)
- Disallow passing non-keyword arguments to :meth:`ExtensionArray.argsort` (:issue:`46134`)
- Disallow passing non-keyword arguments to :meth:`Categorical.sort_values` (:issue:`47618`)
- Disallow passing non-keyword arguments to :meth:`Index.drop_duplicates` and :meth:`Series.drop_duplicates` (:issue:`41485`)
- Disallow passing non-keyword arguments to :meth:`DataFrame.drop_duplicates` except for ``subset`` (:issue:`41485`)
- Disallow passing non-keyword arguments to :meth:`DataFrame.sort_index` and :meth:`Series.sort_index` (:issue:`41506`)
- Disallow passing non-keyword arguments to :meth:`DataFrame.interpolate` and :meth:`Series.interpolate` except for ``method`` (:issue:`41510`)
Expand All @@ -209,6 +216,9 @@ Removal of prior version deprecations/changes
- Disallow passing non-keyword arguments to :func:`read_json` except for ``path_or_buf`` (:issue:`27573`)
- Disallow passing non-keyword arguments to :func:`read_sas` except for ``filepath_or_buffer`` (:issue:`47154`)
- Disallow passing non-keyword arguments to :func:`read_stata` except for ``filepath_or_buffer`` (:issue:`48128`)
- Disallow passing non-keyword arguments to :func:`read_csv` except ``filepath_or_buffer`` (:issue:`41485`)
- Disallow passing non-keyword arguments to :func:`read_table` except ``filepath_or_buffer`` (:issue:`41485`)
- Disallow passing non-keyword arguments to :func:`read_fwf` except ``filepath_or_buffer`` (:issue:`44710`)
- Disallow passing non-keyword arguments to :func:`read_xml` except for ``path_or_buffer`` (:issue:`45133`)
- Disallow passing non-keyword arguments to :meth:`Series.mask` and :meth:`DataFrame.mask` except ``cond`` and ``other`` (:issue:`41580`)
- Disallow passing non-keyword arguments to :meth:`DataFrame.to_stata` except for ``path`` (:issue:`48128`)
Expand Down
8 changes: 2 additions & 6 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
pa_version_under6p0,
pa_version_under7p0,
)
from pandas.util._decorators import (
deprecate_nonkeyword_arguments,
doc,
)
from pandas.util._decorators import doc

from pandas.core.dtypes.common import (
is_array_like,
Expand Down Expand Up @@ -452,13 +449,12 @@ def isna(self) -> npt.NDArray[np.bool_]:
"""
return self._data.is_null().to_numpy()

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def argsort(
self,
*,
ascending: bool = True,
kind: SortKind = "quicksort",
na_position: str = "last",
*args,
**kwargs,
) -> np.ndarray:
order = "ascending" if ascending else "descending"
Expand Down
6 changes: 2 additions & 4 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
Appender,
Substitution,
cache_readonly,
deprecate_nonkeyword_arguments,
)
from pandas.util._exceptions import find_stack_level
from pandas.util._validators import (
Expand Down Expand Up @@ -662,13 +661,12 @@ def _values_for_argsort(self) -> np.ndarray:
# Note: this is used in `ExtensionArray.argsort/argmin/argmax`.
return np.array(self)

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def argsort(
self,
*,
ascending: bool = True,
kind: SortKind = "quicksort",
na_position: str = "last",
*args,
**kwargs,
) -> np.ndarray:
"""
Expand Down Expand Up @@ -699,7 +697,7 @@ def argsort(
# 1. _values_for_argsort : construct the values passed to np.argsort
# 2. argsort : total control over sorting. In case of overriding this,
# it is recommended to also override argmax/argmin
ascending = nv.validate_argsort_with_ascending(ascending, args, kwargs)
ascending = nv.validate_argsort_with_ascending(ascending, (), kwargs)

values = self._values_for_argsort()
return nargsort(
Expand Down
13 changes: 7 additions & 6 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1802,10 +1802,8 @@ def check_for_ordered(self, op) -> None:
"Categorical to an ordered one\n"
)

# error: Signature of "argsort" incompatible with supertype "ExtensionArray"
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def argsort( # type: ignore[override]
self, ascending: bool = True, kind: SortKind = "quicksort", **kwargs
def argsort(
self, *, ascending: bool = True, kind: SortKind = "quicksort", **kwargs
):
"""
Return the indices that would sort the Categorical.
Expand Down Expand Up @@ -1875,9 +1873,12 @@ def sort_values(
) -> None:
...

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def sort_values(
self, inplace: bool = False, ascending: bool = True, na_position: str = "last"
self,
*,
inplace: bool = False,
ascending: bool = True,
na_position: str = "last",
) -> Categorical | None:
"""
Sort the Categorical by category value returning a new
Expand Down
10 changes: 3 additions & 7 deletions pandas/core/arrays/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@
)
from pandas.compat.numpy import function as nv
from pandas.errors import IntCastingNaNError
from pandas.util._decorators import (
Appender,
deprecate_nonkeyword_arguments,
)
from pandas.util._decorators import Appender

from pandas.core.dtypes.cast import LossySetitemError
from pandas.core.dtypes.common import (
Expand Down Expand Up @@ -796,16 +793,15 @@ def __lt__(self, other):
def __le__(self, other):
return self._cmp_method(other, operator.le)

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def argsort(
self,
*,
ascending: bool = True,
kind: SortKind = "quicksort",
na_position: str = "last",
*args,
**kwargs,
) -> np.ndarray:
ascending = nv.validate_argsort_with_ascending(ascending, args, kwargs)
ascending = nv.validate_argsort_with_ascending(ascending, (), kwargs)

if ascending and kind == "quicksort" and na_position == "last":
return np.lexsort((self.right, self.left))
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ def searchsorted(
sorter=sorter,
)

def drop_duplicates(self, keep: DropKeep = "first"):
def drop_duplicates(self, *, keep: DropKeep = "first"):
duplicated = self._duplicated(keep=keep)
# error: Value of type "IndexOpsMixin" is not indexable
return self[~duplicated] # type: ignore[index]
Expand Down
9 changes: 4 additions & 5 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5835,10 +5835,10 @@ def set_index(
) -> None:
...

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "keys"])
def set_index(
self,
keys,
*,
drop: bool = True,
append: bool = False,
inplace: bool = False,
Expand Down Expand Up @@ -6080,10 +6080,10 @@ def reset_index(
) -> DataFrame | None:
...

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "level"])
def reset_index(
self,
level: IndexLabel = None,
*,
drop: bool = False,
inplace: bool = False,
col_level: Hashable = 0,
Expand Down Expand Up @@ -6376,9 +6376,9 @@ def dropna(
) -> None:
...

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def dropna(
self,
*,
axis: Axis = 0,
how: AnyAll | NoDefault = no_default,
thresh: int | NoDefault = no_default,
Expand Down Expand Up @@ -8500,9 +8500,8 @@ def groupby(

@Substitution("")
@Appender(_shared_docs["pivot"])
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def pivot(
self, index=lib.NoDefault, columns=lib.NoDefault, values=lib.NoDefault
self, *, index=lib.NoDefault, columns=lib.NoDefault, values=lib.NoDefault
) -> DataFrame:
from pandas.core.reshape.pivot import pivot

Expand Down
4 changes: 1 addition & 3 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
from pandas.util._decorators import (
Appender,
cache_readonly,
deprecate_nonkeyword_arguments,
doc,
)
from pandas.util._exceptions import (
Expand Down Expand Up @@ -2894,8 +2893,7 @@ def unique(self: _IndexT, level: Hashable | None = None) -> _IndexT:
result = super().unique()
return self._shallow_copy(result)

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def drop_duplicates(self: _IndexT, keep: DropKeep = "first") -> _IndexT:
def drop_duplicates(self: _IndexT, *, keep: DropKeep = "first") -> _IndexT:
"""
Return Index with duplicate values removed.

Expand Down
3 changes: 1 addition & 2 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
from pandas.util._decorators import (
Appender,
Substitution,
deprecate_nonkeyword_arguments,
doc,
)

Expand Down Expand Up @@ -881,11 +880,11 @@ def fillna(self, method, limit=None):
"""
return self._upsample(method, limit=limit)

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "method"])
@doc(NDFrame.interpolate, **_shared_docs_kwargs)
def interpolate(
self,
method: QuantileInterpolation = "linear",
*,
axis: Axis = 0,
limit=None,
inplace: bool = False,
Expand Down
13 changes: 6 additions & 7 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,10 +1409,10 @@ def reset_index(
) -> None:
...

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "level"])
def reset_index(
self,
level: IndexLabel = None,
*,
drop: bool = False,
name: Level = lib.no_default,
inplace: bool = False,
Expand Down Expand Up @@ -2186,23 +2186,22 @@ def unique(self) -> ArrayLike:

@overload
def drop_duplicates(
self, keep: DropKeep = ..., *, inplace: Literal[False] = ...
self, *, keep: DropKeep = ..., inplace: Literal[False] = ...
) -> Series:
...

@overload
def drop_duplicates(self, keep: DropKeep = ..., *, inplace: Literal[True]) -> None:
def drop_duplicates(self, *, keep: DropKeep = ..., inplace: Literal[True]) -> None:
...

@overload
def drop_duplicates(
self, keep: DropKeep = ..., *, inplace: bool = ...
self, *, keep: DropKeep = ..., inplace: bool = ...
) -> Series | None:
...

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def drop_duplicates(
self, keep: DropKeep = "first", inplace: bool = False
self, *, keep: DropKeep = "first", inplace: bool = False
) -> Series | None:
"""
Return Series with duplicate values removed.
Expand Down Expand Up @@ -5687,9 +5686,9 @@ def dropna(
) -> None:
...

@deprecate_nonkeyword_arguments(version=None, allowed_args=["self"])
def dropna(
self,
*,
axis: Axis = 0,
inplace: bool = False,
how: AnyAll | None = None,
Expand Down
7 changes: 3 additions & 4 deletions pandas/io/parsers/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
from pandas.util._decorators import (
Appender,
deprecate_kwarg,
deprecate_nonkeyword_arguments,
)
from pandas.util._exceptions import find_stack_level
from pandas.util._validators import validate_bool_kwarg
Expand Down Expand Up @@ -864,7 +863,6 @@ def read_csv(


@deprecate_kwarg(old_arg_name="mangle_dupe_cols", new_arg_name=None)
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
@Appender(
_doc_read_csv_and_table.format(
func_name="read_csv",
Expand All @@ -877,6 +875,7 @@ def read_csv(
)
def read_csv(
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
*,
sep: str | None | lib.NoDefault = lib.no_default,
delimiter: str | None | lib.NoDefault = None,
# Column and Index Locations and Names
Expand Down Expand Up @@ -1208,7 +1207,6 @@ def read_table(


@deprecate_kwarg(old_arg_name="mangle_dupe_cols", new_arg_name=None)
@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
@Appender(
_doc_read_csv_and_table.format(
func_name="read_table",
Expand All @@ -1221,6 +1219,7 @@ def read_table(
)
def read_table(
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
*,
sep: str | None | lib.NoDefault = lib.no_default,
delimiter: str | None | lib.NoDefault = None,
# Column and Index Locations and Names
Expand Down Expand Up @@ -1307,9 +1306,9 @@ def read_table(
return _read(filepath_or_buffer, kwds)


@deprecate_nonkeyword_arguments(version=None, allowed_args=["filepath_or_buffer"])
def read_fwf(
filepath_or_buffer: FilePath | ReadCsvBuffer[bytes] | ReadCsvBuffer[str],
*,
colspecs: Sequence[tuple[int, int]] | str | None = "infer",
widths: Sequence[int] | None = None,
infer_nrows: int = 100,
Expand Down
12 changes: 0 additions & 12 deletions pandas/tests/frame/methods/test_drop.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,18 +510,6 @@ def test_drop_with_duplicate_columns2(self):
result = df2.drop("C", axis=1)
tm.assert_frame_equal(result, expected)

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

def test_drop_inplace_no_leftover_column_reference(self):
# GH 13934
df = DataFrame({"a": [1, 2, 3]})
Expand Down
12 changes: 0 additions & 12 deletions pandas/tests/frame/methods/test_dropna.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,6 @@ def test_dropna_with_duplicate_columns(self):
result = df.dropna(subset=["A", "C"], how="all")
tm.assert_frame_equal(result, expected)

def test_dropna_pos_args_deprecation(self):
# https://github.com/pandas-dev/pandas/issues/41485
df = DataFrame({"a": [1, 2, 3]})
msg = (
r"In a future version of pandas all arguments of DataFrame\.dropna "
r"will be keyword-only"
)
with tm.assert_produces_warning(FutureWarning, match=msg):
result = df.dropna(1)
expected = DataFrame({"a": [1, 2, 3]})
tm.assert_frame_equal(result, expected)

def test_set_single_column_subset(self):
# GH 41021
df = DataFrame({"A": [1, 2, 3], "B": list("abc"), "C": [4, np.NaN, 5]})
Expand Down
Loading