Skip to content

BUG: series with complex nan #53682

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 5 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 8 additions & 1 deletion pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2485,7 +2485,14 @@ def maybe_convert_objects(ndarray[object] objects,
elif util.is_nan(val):
seen.nan_ = True
mask[i] = True
floats[i] = complexes[i] = val
if util.is_complex_object(val):
floats[i] = fnan
complexes[i] = val
seen.complex_ = True
if not convert_numeric:
break
else:
floats[i] = complexes[i] = val
elif util.is_bool_object(val):
seen.bool_ = True
bools[i] = val
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/generic/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,8 @@ def finalize(self, other, method=None, **kwargs):
result = pd.concat([ser, ser2])
assert result.filename == "foo+bar"
assert result.name is None

def test_series_with_complex_nan(self):
# GH#53627
ser = Series([complex("nan")])
assert np.isnan(ser[0].real) and ser[0].imag == 0