Skip to content

Commit 1f6f178

Browse files
committed
Merge pull request #4820 from jreback/complex
API: Complex compat for Series with ndarray. (GH4819)
2 parents d54b53f + c4279e7 commit 1f6f178

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

doc/source/cookbook.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ panelnd
116116
The :ref:`panelnd<dsintro.panelnd>` docs.
117117

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

121121
.. _cookbook.missing_data:
122122

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ See :ref:`Internal Refactoring<whatsnew_0130.refactoring>`
265265
- Refactor of ``_get_numeric_data/_get_bool_data`` to core/generic.py, allowing Series/Panel functionaility
266266
- Refactor of Series arithmetic with time-like objects (datetime/timedelta/time
267267
etc.) into a separate, cleaned up wrapper class. (:issue:`4613`)
268+
- Complex compat for ``Series`` with ``ndarray``. (:issue:`4819`)
268269

269270
Experimental Features
270271
~~~~~~~~~~~~~~~~~~~~~

pandas/core/series.py

+18
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from pandas import compat
3636
from pandas.util.terminal import get_terminal_size
3737
from pandas.compat import zip, lzip, u, OrderedDict
38+
from pandas.util import rwproperty
3839

3940
import pandas.core.array as pa
4041

@@ -793,6 +794,23 @@ def __array_wrap__(self, result):
793794
def __contains__(self, key):
794795
return key in self.index
795796

797+
# complex
798+
@rwproperty.getproperty
799+
def real(self):
800+
return self.values.real
801+
802+
@rwproperty.setproperty
803+
def real(self, v):
804+
self.values.real = v
805+
806+
@rwproperty.getproperty
807+
def imag(self):
808+
return self.values.imag
809+
810+
@rwproperty.setproperty
811+
def imag(self, v):
812+
self.values.imag = v
813+
796814
# coercion
797815
__float__ = _coerce_method(float)
798816
__long__ = _coerce_method(int)

pandas/tests/test_series.py

+13
Original file line numberDiff line numberDiff line change
@@ -2814,6 +2814,19 @@ def f(x):
28142814
expected = Series(1,index=range(10),dtype='float64')
28152815
#assert_series_equal(result,expected)
28162816

2817+
def test_complexx(self):
2818+
2819+
# GH4819
2820+
# complex access for ndarray compat
2821+
a = np.arange(5)
2822+
b = Series(a + 4j*a)
2823+
tm.assert_almost_equal(a,b.real)
2824+
tm.assert_almost_equal(4*a,b.imag)
2825+
2826+
b.real = np.arange(5)+5
2827+
tm.assert_almost_equal(a+5,b.real)
2828+
tm.assert_almost_equal(4*a,b.imag)
2829+
28172830
def test_underlying_data_conversion(self):
28182831

28192832
# GH 4080

0 commit comments

Comments
 (0)