Skip to content

Commit

Permalink
DEPR: enforce deprecations for kwargs in factorize, FrozenNDArray.ser… (
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and proost committed Dec 19, 2019
1 parent b39f085 commit 59b3838
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 42 deletions.
4 changes: 4 additions & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
- Removed the previously deprecated ``assert_raises_regex`` function in ``pandas.util.testing`` (:issue:`29174`)
- Removed :meth:`Index.is_lexsorted_for_tuple` (:issue:`29305`)
- Removed support for nexted renaming in :meth:`DataFrame.aggregate`, :meth:`Series.aggregate`, :meth:`DataFrameGroupBy.aggregate`, :meth:`SeriesGroupBy.aggregate`, :meth:`Rolling.aggregate` (:issue:`29608`)
- Removed previously deprecated "order" argument from :func:`factorize` (:issue:`19751`)
- Removed previously deprecated "v" argument from :meth:`FrozenNDarray.searchsorted`, use "value" instead (:issue:`22672`)
- Removed previously deprecated "raise_conflict" argument from :meth:`DataFrame.update`, use "errors" instead (:issue:`23585`)
- Removed previously deprecated keyword "n" from :meth:`DatetimeIndex.shift`, :meth:`TimedeltaIndex.shift`, :meth:`PeriodIndex.shift`, use "periods" instead (:issue:`22458`)
-

.. _whatsnew_1000.performance:
Expand Down
19 changes: 3 additions & 16 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from pandas._libs import Timestamp, algos, hashtable as htable, lib
from pandas._libs.tslib import iNaT
from pandas.util._decorators import Appender, Substitution, deprecate_kwarg
from pandas.util._decorators import Appender, Substitution

from pandas.core.dtypes.cast import (
construct_1d_object_array_from_listlike,
Expand Down Expand Up @@ -494,7 +494,7 @@ def _factorize_array(
Parameters
----------
%(values)s%(sort)s%(order)s
%(values)s%(sort)s
na_sentinel : int, default -1
Value to mark "not found".
%(size_hint)s\
Expand Down Expand Up @@ -585,14 +585,6 @@ def _factorize_array(
coerced to ndarrays before factorization.
"""
),
order=dedent(
"""\
order : None
.. deprecated:: 0.23.0
This parameter has no effect and is deprecated.
"""
),
sort=dedent(
"""\
sort : bool, default False
Expand All @@ -608,13 +600,8 @@ def _factorize_array(
),
)
@Appender(_shared_docs["factorize"])
@deprecate_kwarg(old_arg_name="order", new_arg_name=None)
def factorize(
values,
sort: bool = False,
order=None,
na_sentinel: int = -1,
size_hint: Optional[int] = None,
values, sort: bool = False, na_sentinel: int = -1, size_hint: Optional[int] = None,
) -> Tuple[np.ndarray, Union[np.ndarray, ABCIndex]]:
# Implementation notes: This method is responsible for 3 things
# 1.) coercing data to array-like (ndarray, Index, extension array)
Expand Down
5 changes: 0 additions & 5 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5528,11 +5528,6 @@ def combiner(x, y):

return self.combine(other, combiner, overwrite=False)

@deprecate_kwarg(
old_arg_name="raise_conflict",
new_arg_name="errors",
mapping={False: "ignore", True: "raise"},
)
def update(
self, other, join="left", overwrite=True, filter_func=None, errors="ignore"
):
Expand Down
7 changes: 3 additions & 4 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pandas._libs.algos import unique_deltas
from pandas.compat.numpy import function as nv
from pandas.errors import AbstractMethodError
from pandas.util._decorators import Appender, cache_readonly, deprecate_kwarg
from pandas.util._decorators import Appender, cache_readonly

from pandas.core.dtypes.common import (
ensure_int64,
Expand Down Expand Up @@ -732,8 +732,7 @@ def astype(self, dtype, copy=True):
# _data.astype call above
return Index(new_values, dtype=new_values.dtype, name=self.name, copy=False)

@deprecate_kwarg(old_arg_name="n", new_arg_name="periods")
def shift(self, periods, freq=None):
def shift(self, periods=1, freq=None):
"""
Shift index by desired number of time frequency increments.
Expand All @@ -742,7 +741,7 @@ def shift(self, periods, freq=None):
Parameters
----------
periods : int
periods : int, default 1
Number of periods (or increments) to shift by,
can be positive or negative.
Expand Down
3 changes: 0 additions & 3 deletions pandas/core/indexes/frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

import numpy as np

from pandas.util._decorators import deprecate_kwarg

from pandas.core.dtypes.cast import coerce_indexer_dtype

from pandas.core.base import PandasObject
Expand Down Expand Up @@ -155,7 +153,6 @@ def __repr__(self) -> str:
prepr = pprint_thing(self, escape_chars=("\t", "\r", "\n"), quote_strings=True)
return f"{type(self).__name__}({prepr}, dtype='{self.dtype}')"

@deprecate_kwarg(old_arg_name="v", new_arg_name="value")
def searchsorted(self, value, side="left", sorter=None):
"""
Find indices to insert `value` so as to maintain order.
Expand Down
7 changes: 0 additions & 7 deletions pandas/tests/frame/test_combine_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,6 @@ def test_update_raise_on_overlap(self):
with pytest.raises(ValueError, match="Data overlaps"):
df.update(other, errors="raise")

@pytest.mark.parametrize("raise_conflict", [True, False])
def test_update_deprecation(self, raise_conflict):
df = DataFrame([[1.5, 1, 3.0]])
other = DataFrame()
with tm.assert_produces_warning(FutureWarning):
df.update(other, raise_conflict=raise_conflict)

def test_update_from_non_df(self):
d = {"a": Series([1, 2, 3, 4]), "b": Series([5, 6, 7, 8])}
df = DataFrame(d)
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/indexes/datetimes/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,6 @@ def test_shift_periods(self):
idx = pd.date_range(start=START, end=END, periods=3)
tm.assert_index_equal(idx.shift(periods=0), idx)
tm.assert_index_equal(idx.shift(0), idx)
with tm.assert_produces_warning(FutureWarning, check_stacklevel=True):
tm.assert_index_equal(idx.shift(n=0), idx)

def test_pickle_unpickle(self):
unpickled = tm.round_trip_pickle(self.rng)
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/indexes/period/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,3 @@ def test_shift_periods(self):
idx = period_range(freq="A", start="1/1/2001", end="12/1/2009")
tm.assert_index_equal(idx.shift(periods=0), idx)
tm.assert_index_equal(idx.shift(0), idx)
with tm.assert_produces_warning(FutureWarning, check_stacklevel=True):
tm.assert_index_equal(idx.shift(n=0), idx)
3 changes: 1 addition & 2 deletions pandas/tests/indexes/test_frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,4 @@ def test_searchsorted(self):
expected = 2
assert self.container.searchsorted(7) == expected

with tm.assert_produces_warning(FutureWarning):
assert self.container.searchsorted(v=7) == expected
assert self.container.searchsorted(value=7) == expected
2 changes: 1 addition & 1 deletion pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_deprecate_order(self):
# gh 19727 - check warning is raised for deprecated keyword, order.
# Test not valid once order keyword is removed.
data = np.array([2 ** 63, 1, 2 ** 63], dtype=np.uint64)
with tm.assert_produces_warning(expected_warning=FutureWarning):
with pytest.raises(TypeError, match="got an unexpected keyword"):
algos.factorize(data, order=True)
with tm.assert_produces_warning(False):
algos.factorize(data)
Expand Down

0 comments on commit 59b3838

Please sign in to comment.