Skip to content

Commit

Permalink
DEPR: remove real, imag, put, and str.partition kwarg (#29986)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and jreback committed Dec 4, 2019
1 parent 26c9d02 commit 42ffec1
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 100 deletions.
1 change: 0 additions & 1 deletion doc/redirects.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion doc/source/reference/series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ Attributes
Series.empty
Series.dtypes
Series.name
Series.put

Conversion
----------
Expand Down
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
59 changes: 1 addition & 58 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 1 addition & 6 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
20 changes: 0 additions & 20 deletions pandas/tests/series/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
7 changes: 0 additions & 7 deletions pandas/tests/series/test_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 5 additions & 7 deletions pandas/tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 42ffec1

Please sign in to comment.