diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 27a72014a9f8e..28bf796be404a 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -604,7 +604,10 @@ Other deprecations - The :meth:`Series.ftype`, :meth:`Series.ftypes` and :meth:`DataFrame.ftypes` methods are deprecated and will be removed in a future version. Instead, use :meth:`Series.dtype` and :meth:`DataFrame.dtypes` (:issue:`26705`). - :meth:`Timedelta.resolution` is deprecated and replaced with :meth:`Timedelta.resolution_string`. In a future version, :meth:`Timedelta.resolution` will be changed to behave like the standard library :attr:`timedelta.resolution` (:issue:`21344`) -- func:`read_table` has been undeprecated. (:issue:`25220`) +- :func:`read_table` has been undeprecated. (:issue:`25220`) +- :attr:`Index.dtype_str` is deprecated. (:issue:`18262`) +- :attr:`Series.imag` and :attr:`Series.real` are deprecated. (:issue:`18262`) +- :meth:`Series.put` is deprecated. (:issue:`18262`) .. _whatsnew_0250.prior_deprecations: diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 9f5e3e8ee77f0..a1d591458fba3 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1989,9 +1989,7 @@ def _repr_categories_info(self): """ category_strs = self._repr_categories() - dtype = getattr(self.categories, 'dtype_str', - str(self.categories.dtype)) - + dtype = str(self.categories.dtype) levheader = "Categories ({length}, {dtype}): ".format( length=len(self.categories), dtype=dtype) width, height = get_terminal_size() diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index c96d9e2c5f77a..6a708536689c4 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -690,7 +690,12 @@ def dtype(self): def dtype_str(self): """ Return the dtype str of the underlying data. + + .. deprecated:: 0.25.0 """ + warnings.warn('`dtype_str` has been deprecated. Call `str` on the ' + 'dtype attribute instead.', FutureWarning, + stacklevel=2) return str(self.dtype) def ravel(self, order='C'): diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index 834a3bc3d8bbb..cc8b241bedba1 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -1275,7 +1275,7 @@ def _ensure_numeric(x): except (TypeError, ValueError): x = x.astype(np.float64) else: - if not np.any(x.imag): + if not np.any(np.imag(x)): x = x.real elif not (is_float(x) or is_integer(x) or is_complex(x)): try: diff --git a/pandas/core/series.py b/pandas/core/series.py index 730a96f5435a1..31cb7432b3ae1 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -617,10 +617,14 @@ 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): @@ -793,7 +797,11 @@ def __array_prepare__(self, result, context=None): def real(self): """ Return the real value of vector. + + .. deprecated 0.25.0 """ + warnings.warn("`real` has be deprecated and will be removed in a " + "future verison", FutureWarning, stacklevel=2) return self.values.real @real.setter @@ -804,7 +812,11 @@ def real(self, v): def imag(self): """ Return imag value of vector. + + .. deprecated 0.25.0 """ + warnings.warn("`imag` has be deprecated and will be removed in a " + "future verison", FutureWarning, stacklevel=2) return self.values.imag @imag.setter diff --git a/pandas/core/util/hashing.py b/pandas/core/util/hashing.py index 93074f5afa2b3..a916f2f06df21 100644 --- a/pandas/core/util/hashing.py +++ b/pandas/core/util/hashing.py @@ -269,7 +269,7 @@ def hash_array(vals, encoding='utf8', hash_key=None, categorize=True): # we'll be working with everything as 64-bit values, so handle this # 128-bit value early if np.issubdtype(dtype, np.complex128): - return hash_array(vals.real) + 23 * hash_array(vals.imag) + return hash_array(np.real(vals)) + 23 * hash_array(np.imag(vals)) # First, turn whatever array this is into unsigned 64-bit ints, if we can # manage it. diff --git a/pandas/io/packers.py b/pandas/io/packers.py index 4a273bfe2decb..cef0af3edbb20 100644 --- a/pandas/io/packers.py +++ b/pandas/io/packers.py @@ -523,16 +523,16 @@ def encode(obj): return {'typ': 'np_scalar', 'sub_typ': 'np_complex', 'dtype': obj.dtype.name, - 'real': obj.real.__repr__(), - 'imag': obj.imag.__repr__()} + 'real': np.real(obj).__repr__(), + 'imag': np.imag(obj).__repr__()} else: return {'typ': 'np_scalar', 'dtype': obj.dtype.name, 'data': obj.__repr__()} elif isinstance(obj, complex): return {'typ': 'np_complex', - 'real': obj.real.__repr__(), - 'imag': obj.imag.__repr__()} + 'real': np.real(obj).__repr__(), + 'imag': np.imag(obj).__repr__()} return obj diff --git a/pandas/tests/indexes/multi/test_format.py b/pandas/tests/indexes/multi/test_format.py index 8315478d85125..85d30b8f6de6b 100644 --- a/pandas/tests/indexes/multi/test_format.py +++ b/pandas/tests/indexes/multi/test_format.py @@ -8,9 +8,10 @@ def test_dtype_str(indices): - dtype = indices.dtype_str - assert isinstance(dtype, str) - assert dtype == str(indices.dtype) + with tm.assert_produces_warning(FutureWarning): + dtype = indices.dtype_str + assert isinstance(dtype, str) + assert dtype == str(indices.dtype) def test_format(idx): diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index 2f3f15101e7ca..a70f67557bfc2 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -132,12 +132,14 @@ def test_shallow_copy_changing_freq_raises(self): def test_dtype_str(self): pi = pd.PeriodIndex([], freq='M') - assert pi.dtype_str == 'period[M]' - assert pi.dtype_str == str(pi.dtype) + with tm.assert_produces_warning(FutureWarning): + assert pi.dtype_str == 'period[M]' + assert pi.dtype_str == str(pi.dtype) - pi = pd.PeriodIndex([], freq='3M') - assert pi.dtype_str == 'period[3M]' - assert pi.dtype_str == str(pi.dtype) + with tm.assert_produces_warning(FutureWarning): + pi = pd.PeriodIndex([], freq='3M') + assert pi.dtype_str == 'period[3M]' + assert pi.dtype_str == str(pi.dtype) def test_view_asi8(self): idx = pd.PeriodIndex([], freq='M') diff --git a/pandas/tests/indexes/test_common.py b/pandas/tests/indexes/test_common.py index 451fb2ed7906d..3cb907c6f5844 100644 --- a/pandas/tests/indexes/test_common.py +++ b/pandas/tests/indexes/test_common.py @@ -155,9 +155,10 @@ def test_set_name_methods(self, indices): assert indices.names == [name] def test_dtype_str(self, indices): - dtype = indices.dtype_str - assert isinstance(dtype, str) - assert dtype == str(indices.dtype) + with tm.assert_produces_warning(FutureWarning): + dtype = indices.dtype_str + assert isinstance(dtype, str) + assert dtype == str(indices.dtype) def test_hash_error(self, indices): index = indices diff --git a/pandas/tests/series/test_dtypes.py b/pandas/tests/series/test_dtypes.py index 392163228398b..b9146534d10f1 100644 --- a/pandas/tests/series/test_dtypes.py +++ b/pandas/tests/series/test_dtypes.py @@ -428,17 +428,25 @@ 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, b.real) - tm.assert_numpy_array_equal(4 * a, b.imag) + 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, b.real) - tm.assert_numpy_array_equal(4 * a, b.imag) + 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 diff --git a/pandas/tests/series/test_internals.py b/pandas/tests/series/test_internals.py index 29846f10dae33..0b62624ad2696 100644 --- a/pandas/tests/series/test_internals.py +++ b/pandas/tests/series/test_internals.py @@ -221,3 +221,10 @@ 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_nanops.py b/pandas/tests/test_nanops.py index ad035f9c0158d..6e7b34a0632ad 100644 --- a/pandas/tests/test_nanops.py +++ b/pandas/tests/test_nanops.py @@ -144,9 +144,9 @@ def _coerce_tds(targ, res): # but nanops doesn't, so make that an exception elif targ.dtype.kind == 'O': raise - tm.assert_almost_equal(targ.real, res.real, + tm.assert_almost_equal(np.real(targ), np.real(res), check_dtype=check_dtype) - tm.assert_almost_equal(targ.imag, res.imag, + tm.assert_almost_equal(np.imag(targ), np.imag(res), check_dtype=check_dtype) def check_fun_data(self, testfunc, targfunc, testarval, targarval,