Skip to content

API: Complex compat for Series with ndarray. (GH4819) #4820

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 1 commit into from
Sep 11, 2013
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion doc/source/cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ panelnd
The :ref:`panelnd<dsintro.panelnd>` docs.

`Construct a 5D panelnd
http://stackoverflow.com/questions/18748598/why-my-panelnd-factory-throwing-a-keyerror`__
<http://stackoverflow.com/questions/18748598/why-my-panelnd-factory-throwing-a-keyerror>`__

.. _cookbook.missing_data:

Expand Down
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ See :ref:`Internal Refactoring<whatsnew_0130.refactoring>`
- Refactor of ``_get_numeric_data/_get_bool_data`` to core/generic.py, allowing Series/Panel functionaility
- Refactor of Series arithmetic with time-like objects (datetime/timedelta/time
etc.) into a separate, cleaned up wrapper class. (:issue:`4613`)
- Complex compat for ``Series`` with ``ndarray``. (:issue:`4819`)

Experimental Features
~~~~~~~~~~~~~~~~~~~~~
Expand Down
18 changes: 18 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from pandas import compat
from pandas.util.terminal import get_terminal_size
from pandas.compat import zip, lzip, u, OrderedDict
from pandas.util import rwproperty

import pandas.core.array as pa

Expand Down Expand Up @@ -793,6 +794,23 @@ def __array_wrap__(self, result):
def __contains__(self, key):
return key in self.index

# complex
@rwproperty.getproperty
def real(self):
return self.values.real

@rwproperty.setproperty
def real(self, v):
self.values.real = v

@rwproperty.getproperty
def imag(self):
return self.values.imag

@rwproperty.setproperty
def imag(self, v):
self.values.imag = v

# coercion
__float__ = _coerce_method(float)
__long__ = _coerce_method(int)
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2814,6 +2814,19 @@ def f(x):
expected = Series(1,index=range(10),dtype='float64')
#assert_series_equal(result,expected)

def test_complexx(self):

# GH4819
# complex access for ndarray compat
a = np.arange(5)
b = Series(a + 4j*a)
tm.assert_almost_equal(a,b.real)
tm.assert_almost_equal(4*a,b.imag)

b.real = np.arange(5)+5
tm.assert_almost_equal(a+5,b.real)
tm.assert_almost_equal(4*a,b.imag)

def test_underlying_data_conversion(self):

# GH 4080
Expand Down