Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,9 @@ 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`)
- :attr:`Index.dtype_str` is deprecated. (:issue:`18262`)
- :attr:`Series.imag` and :attr:`Series.real` is deprecated. (:issue:`18262`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is -> are

- :meth:`Series.put` is deprecated. (:issue:`18262`)

.. _whatsnew_0250.prior_deprecations:

Expand Down
5 changes: 5 additions & 0 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.', DeprecationWarning,
stacklevel=2)
return str(self.dtype)

def ravel(self, order='C'):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.', DeprecationWarning, stacklevel=2)
self._values.put(*args, **kwargs)

def __len__(self):
Expand Down Expand Up @@ -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", DeprecationWarning, stacklevel=2)
return self.values.real

@real.setter
Expand All @@ -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", DeprecationWarning, stacklevel=2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeprecationWarning -> FutureWaring on all of these

return self.values.imag

@imag.setter
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/util/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions pandas/io/packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions pandas/tests/indexes/multi/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(DeprecationWarning):
dtype = indices.dtype_str
assert isinstance(dtype, str)
assert dtype == str(indices.dtype)


def test_format(idx):
Expand Down
14 changes: 8 additions & 6 deletions pandas/tests/indexes/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

pi = pd.PeriodIndex([], freq='3M')
assert pi.dtype_str == 'period[3M]'
assert pi.dtype_str == str(pi.dtype)
with tm.assert_produces_warning(DeprecationWarning):
assert pi.dtype_str == 'period[M]'
assert pi.dtype_str == str(pi.dtype)

with tm.assert_produces_warning(DeprecationWarning):
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')
Expand Down
7 changes: 4 additions & 3 deletions pandas/tests/indexes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(DeprecationWarning):
dtype = indices.dtype_str
assert isinstance(dtype, str)
assert dtype == str(indices.dtype)

def test_hash_error(self, indices):
index = indices
Expand Down
16 changes: 12 additions & 4 deletions pandas/tests/series/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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::DeprecationWarning')
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(DeprecationWarning):
s.imag
s.real

def test_arg_for_errors_in_astype(self):
# see gh-14878
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/series/test_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(DeprecationWarning):
s.put(0, 0)
4 changes: 2 additions & 2 deletions pandas/tests/test_nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down