Skip to content

BUG: Bug in setting complex dtypes via boolean indexing (GH6345) #6347

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
Feb 14, 2014
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
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Bug Fixes
- Bug in ``DataFrame.replace()`` when passing a non- ``bool``
``to_replace`` argument (:issue:`6332`)
- Raise when trying to align on different levels of a multi-index assignment (:issue:`3738`)
- Bug in setting complex dtypes via boolean indexing (:issue:`6345`)

pandas 0.13.1
-------------
Expand Down
6 changes: 5 additions & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,11 @@ class ComplexBlock(FloatOrComplexBlock):
is_complex = True

def _can_hold_element(self, element):
return isinstance(element, complex)
if is_list_like(element):
element = np.array(element)
return issubclass(element.dtype.type, (np.floating, np.integer, np.complexfloating))
return (isinstance(element, (float, int, complex, np.float_, np.int_)) and
not isinstance(bool, np.bool_))

def _try_cast(self, element):
try:
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -8736,6 +8736,13 @@ def create():
result = df.where(pd.notnull(df),DataFrame(1,index=df.index,columns=df.columns))
assert_frame_equal(result, expected)

def test_where_complex(self):
# GH 6345
expected = DataFrame([[1+1j, 2], [np.nan, 4+1j]], columns=['a', 'b'])
df = DataFrame([[1+1j, 2], [5+1j, 4+1j]], columns=['a', 'b'])
df[df.abs() >= 5] = np.nan
assert_frame_equal(df,expected)

def test_mask(self):
df = DataFrame(np.random.randn(5, 3))
cond = df > 0
Expand Down