8000 DEPR: Series.put, Series.real, Series.imag, Index.dtype_str by mroeschke · Pull Request #27106 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

DEPR: Series.put, Series.real, Series.imag, Index.dtype_str #27106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove imag/real
  • Loading branch information
Matt Roeschke committed Jun 28, 2019
commit b9f21f3a380e77de359a1131dc659aa6d16a42a2
8000
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ Other deprecations
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:``)
-
-

.. _whatsnew_0250.prior_deprecations:

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
8 changes: 8 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,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 +808,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
14 changes: 10 additions & 4 deletions pandas/tests/series/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,18 @@ def test_complex(self):
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):
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
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
0