From 506b238b30eb304415c66237c7e555755e08245e Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 4 Dec 2019 05:58:42 -0800 Subject: [PATCH] DEPR: remove real, imag, put, and str.partition kwarg (#29986) --- doc/redirects.csv | 1 - doc/source/reference/series.rst | 1 - doc/source/whatsnew/v1.0.0.rst | 3 ++ pandas/core/series.py | 59 +-------------------------- pandas/core/strings.py | 7 +--- pandas/tests/series/test_dtypes.py | 20 --------- pandas/tests/series/test_internals.py | 7 ---- pandas/tests/test_strings.py | 12 +++--- 8 files changed, 10 insertions(+), 100 deletions(-) diff --git a/doc/redirects.csv b/doc/redirects.csv index 599ad6d28a8f5..61902f3134a4d 100644 --- a/doc/redirects.csv +++ b/doc/redirects.csv @@ -1119,7 +1119,6 @@ generated/pandas.Series.pow,../reference/api/pandas.Series.pow generated/pandas.Series.prod,../reference/api/pandas.Series.prod generated/pandas.Series.product,../reference/api/pandas.Series.product generated/pandas.Series.ptp,../reference/api/pandas.Series.ptp -generated/pandas.Series.put,../reference/api/pandas.Series.put generated/pandas.Series.quantile,../reference/api/pandas.Series.quantile generated/pandas.Series.radd,../reference/api/pandas.Series.radd generated/pandas.Series.rank,../reference/api/pandas.Series.rank diff --git a/doc/source/reference/series.rst b/doc/source/reference/series.rst index 2485b94ab4d09..e13b4ed98a38b 100644 --- a/doc/source/reference/series.rst +++ b/doc/source/reference/series.rst @@ -39,7 +39,6 @@ Attributes Series.empty Series.dtypes Series.name - Series.put Conversion ---------- diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 4eb5f350cad8e..5c9543580be26 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -565,6 +565,9 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. - Passing multiple axes to :meth:`DataFrame.dropna` is no longer supported (:issue:`20995`) - Removed previously deprecated :meth:`Series.nonzero`, use `to_numpy().nonzero()` instead (:issue:`24048`) - Passing floating dtype ``codes`` to :meth:`Categorical.from_codes` is no longer supported, pass ``codes.astype(np.int64)`` instead (:issue:`21775`) +- :meth:`Series.str.partition` and :meth:`Series.str.rpartition` no longer accept "pat" keyword, use "sep" instead (:issue:`23767`) +- Removed the previously deprecated :meth:`Series.put` (:issue:`27106`) +- Removed the previously deprecated :attr:`Series.real`, :attr:`Series.imag` (:issue:`27106`) - Removed the previously deprecated :meth:`Series.to_dense`, :meth:`DataFrame.to_dense` (:issue:`26684`) - Removed the previously deprecated :meth:`Index.dtype_str`, use ``str(index.dtype)`` instead (:issue:`27106`) - :meth:`Categorical.ravel` returns a :class:`Categorical` instead of a ``ndarray`` (:issue:`27199`) diff --git a/pandas/core/series.py b/pandas/core/series.py index 302d4b591fc1e..410b10a69ecd5 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -158,7 +158,7 @@ class Series(base.IndexOpsMixin, generic.NDFrame): _deprecations = ( base.IndexOpsMixin._deprecations | generic.NDFrame._deprecations - | frozenset(["compress", "valid", "real", "imag", "put", "ptp", "nonzero"]) + | frozenset(["compress", "ptp"]) ) # Override cache_readonly bc Series is mutable @@ -528,23 +528,6 @@ def compress(self, condition, *args, **kwargs): nv.validate_compress(args, kwargs) return self[condition] - def put(self, *args, **kwargs): - """ - Apply the `put` method to its `values` attribute if it has one. - - .. deprecated:: 0.25.0 - - See Also - -------- - numpy.ndarray.put - """ - warnings.warn( - "`put` has been deprecated and will be removed in a future version.", - FutureWarning, - stacklevel=2, - ) - self._values.put(*args, **kwargs) - def __len__(self) -> int: """ Return the length of the Series. @@ -777,46 +760,6 @@ def __array__(self, dtype=None): # ---------------------------------------------------------------------- # Unary Methods - @property - def real(self): - """ - Return the real value of vector. - - .. deprecated:: 0.25.0 - """ - warnings.warn( - "`real` is deprecated and will be removed in a future version. " - "To eliminate this warning for a Series `ser`, use " - "`np.real(ser.to_numpy())` or `ser.to_numpy().real`.", - FutureWarning, - stacklevel=2, - ) - return self.values.real - - @real.setter - def real(self, v): - self.values.real = v - - @property - def imag(self): - """ - Return imag value of vector. - - .. deprecated:: 0.25.0 - """ - warnings.warn( - "`imag` is deprecated and will be removed in a future version. " - "To eliminate this warning for a Series `ser`, use " - "`np.imag(ser.to_numpy())` or `ser.to_numpy().imag`.", - FutureWarning, - stacklevel=2, - ) - return self.values.imag - - @imag.setter - def imag(self, v): - self.values.imag = v - # coercion __float__ = _coerce_method(float) __long__ = _coerce_method(int) diff --git a/pandas/core/strings.py b/pandas/core/strings.py index 04c87e264550b..6cc102dce3b9c 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -9,7 +9,7 @@ import pandas._libs.lib as lib import pandas._libs.ops as libops -from pandas.util._decorators import Appender, deprecate_kwarg +from pandas.util._decorators import Appender from pandas.core.dtypes.common import ( ensure_object, @@ -2628,9 +2628,6 @@ def rsplit(self, pat=None, n=-1, expand=False): ---------- sep : str, default whitespace String to split on. - pat : str, default whitespace - .. deprecated:: 0.24.0 - Use ``sep`` instead. expand : bool, default True If True, return DataFrame/MultiIndex expanding dimensionality. If False, return Series/Index. @@ -2708,7 +2705,6 @@ def rsplit(self, pat=None, n=-1, expand=False): "also": "rpartition : Split the string at the last occurrence of `sep`.", } ) - @deprecate_kwarg(old_arg_name="pat", new_arg_name="sep") @forbid_nonstring_types(["bytes"]) def partition(self, sep=" ", expand=True): f = lambda x: x.partition(sep) @@ -2724,7 +2720,6 @@ def partition(self, sep=" ", expand=True): "also": "partition : Split the string at the first occurrence of `sep`.", } ) - @deprecate_kwarg(old_arg_name="pat", new_arg_name="sep") @forbid_nonstring_types(["bytes"]) def rpartition(self, sep=" ", expand=True): f = lambda x: x.rpartition(sep) diff --git a/pandas/tests/series/test_dtypes.py b/pandas/tests/series/test_dtypes.py index 0dc64651e8d58..065be966efa49 100644 --- a/pandas/tests/series/test_dtypes.py +++ b/pandas/tests/series/test_dtypes.py @@ -411,26 +411,6 @@ def test_astype_empty_constructor_equality(self, dtype): as_type_empty = Series([]).astype(dtype) tm.assert_series_equal(init_empty, as_type_empty) - @pytest.mark.filterwarnings("ignore::FutureWarning") - def test_complex(self): - # see gh-4819: complex access for ndarray compat - a = np.arange(5, dtype=np.float64) - b = Series(a + 4j * a) - - tm.assert_numpy_array_equal(a, np.real(b)) - tm.assert_numpy_array_equal(4 * a, np.imag(b)) - - b.real = np.arange(5) + 5 - tm.assert_numpy_array_equal(a + 5, np.real(b)) - tm.assert_numpy_array_equal(4 * a, np.imag(b)) - - def test_real_imag_deprecated(self): - # GH 18262 - s = pd.Series([1]) - with tm.assert_produces_warning(FutureWarning): - s.imag - s.real - def test_arg_for_errors_in_astype(self): # see gh-14878 s = Series([1, 2, 3]) diff --git a/pandas/tests/series/test_internals.py b/pandas/tests/series/test_internals.py index 187c5d90407ce..efcb500a0b79f 100644 --- a/pandas/tests/series/test_internals.py +++ b/pandas/tests/series/test_internals.py @@ -242,10 +242,3 @@ def test_hasnans_unchached_for_series(): ser.iloc[-1] = np.nan assert ser.hasnans is True assert Series.hasnans.__doc__ == pd.Index.hasnans.__doc__ - - -def test_put_deprecated(): - # GH 18262 - s = pd.Series([1]) - with tm.assert_produces_warning(FutureWarning): - s.put(0, 0) diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index 0e2f8ee6543e1..cf52e286a47a5 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -2966,23 +2966,21 @@ def test_partition_with_name(self): assert res.nlevels == 1 tm.assert_index_equal(res, exp) - def test_partition_deprecation(self): + def test_partition_sep_kwarg(self): # GH 22676; depr kwarg "pat" in favor of "sep" values = Series(["a_b_c", "c_d_e", np.nan, "f_g_h"]) # str.partition # using sep -> no warning expected = values.str.partition(sep="_") - with tm.assert_produces_warning(FutureWarning): - result = values.str.partition(pat="_") - tm.assert_frame_equal(result, expected) + result = values.str.partition("_") + tm.assert_frame_equal(result, expected) # str.rpartition # using sep -> no warning expected = values.str.rpartition(sep="_") - with tm.assert_produces_warning(FutureWarning): - result = values.str.rpartition(pat="_") - tm.assert_frame_equal(result, expected) + result = values.str.rpartition("_") + tm.assert_frame_equal(result, expected) def test_pipe_failures(self): # #2119