From 68af5f6cf9ed2a7a55374920682fb030a80dd923 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 20 Nov 2019 04:24:30 -0800 Subject: [PATCH] =?UTF-8?q?DEPR:=20enforce=20deprecations=20for=20kwargs?= =?UTF-8?q?=20in=20factorize,=20FrozenNDArray.ser=E2=80=A6=20(#29732)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/source/whatsnew/v1.0.0.rst | 4 ++++ pandas/core/algorithms.py | 19 +++---------------- pandas/core/frame.py | 5 ----- pandas/core/indexes/datetimelike.py | 7 +++---- pandas/core/indexes/frozen.py | 3 --- pandas/tests/frame/test_combine_concat.py | 7 ------- pandas/tests/indexes/datetimes/test_ops.py | 2 -- .../tests/indexes/period/test_arithmetic.py | 2 -- pandas/tests/indexes/test_frozen.py | 3 +-- pandas/tests/test_algos.py | 2 +- 10 files changed, 12 insertions(+), 42 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index bfc5cac7339ca..af16e225c1500 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -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: diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index ea75d46048e63..e3f1ae78efcec 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -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, @@ -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\ @@ -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 @@ -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) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 0b76566adf802..5baba0bae1d45 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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" ): diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index b8670b765ca90..df3420ea14e24 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -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, @@ -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. @@ -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. diff --git a/pandas/core/indexes/frozen.py b/pandas/core/indexes/frozen.py index 1b33269d404d6..2c9521d23f71a 100644 --- a/pandas/core/indexes/frozen.py +++ b/pandas/core/indexes/frozen.py @@ -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 @@ -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. diff --git a/pandas/tests/frame/test_combine_concat.py b/pandas/tests/frame/test_combine_concat.py index 12d06dc517f19..e72de487abb2f 100644 --- a/pandas/tests/frame/test_combine_concat.py +++ b/pandas/tests/frame/test_combine_concat.py @@ -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) diff --git a/pandas/tests/indexes/datetimes/test_ops.py b/pandas/tests/indexes/datetimes/test_ops.py index 2ec267c66091b..2944767ba4c02 100644 --- a/pandas/tests/indexes/datetimes/test_ops.py +++ b/pandas/tests/indexes/datetimes/test_ops.py @@ -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) diff --git a/pandas/tests/indexes/period/test_arithmetic.py b/pandas/tests/indexes/period/test_arithmetic.py index 80e4b1fe1e430..f8274a82f1b6f 100644 --- a/pandas/tests/indexes/period/test_arithmetic.py +++ b/pandas/tests/indexes/period/test_arithmetic.py @@ -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) diff --git a/pandas/tests/indexes/test_frozen.py b/pandas/tests/indexes/test_frozen.py index 712feb7b8ef61..c7b219b5ee890 100644 --- a/pandas/tests/indexes/test_frozen.py +++ b/pandas/tests/indexes/test_frozen.py @@ -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 diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index baf78d7188b41..9e89a1b6f0467 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -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)