Skip to content

Commit 756f241

Browse files
committed
Merge pull request #7428 from toddrjen/nancomplex
make nanops._maybe_null_out work with complex numbers ( issue #7353 )
2 parents eb41429 + 8698f2c commit 756f241

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

doc/source/v0.14.1.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ Bug Fixes
213213
- Bug where bool objects were converted to ``nan`` in ``convert_objects``
214214
(:issue:`7416`).
215215
- Bug in ``quantile`` ignoring the axis keyword argument (:issue`7306`)
216-
216+
- Bug where ``nanops._maybe_null_out`` doesn't work with complex numbers
217+
(:issue:`7353`)
217218

218219

219220

pandas/core/nanops.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,10 @@ def _maybe_null_out(result, axis, mask):
547547
if axis is not None:
548548
null_mask = (mask.shape[axis] - mask.sum(axis)) == 0
549549
if null_mask.any():
550-
result = result.astype('f8')
550+
if np.iscomplexobj(result):
551+
result = result.astype('c16')
552+
else:
553+
result = result.astype('f8')
551554
result[null_mask] = np.nan
552555
else:
553556
null_mask = mask.size - mask.sum()

pandas/tests/test_nanops.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ def test_nanall(self):
239239

240240
def test_nansum(self):
241241
self.check_funs(nanops.nansum, np.sum,
242-
allow_complex=False,
243242
allow_str=False, allow_date=False)
244243

245244
def _nanmean_wrap(self, value, *args, **kwargs):
@@ -291,13 +290,11 @@ def _minmax_wrap(self, value, axis=None, func=None):
291290
def test_nanmin(self):
292291
func = partial(self._minmax_wrap, func=np.min)
293292
self.check_funs(nanops.nanmin, func,
294-
allow_complex=False,
295293
allow_str=False, allow_obj=False)
296294

297295
def test_nanmax(self):
298296
func = partial(self._minmax_wrap, func=np.max)
299297
self.check_funs(nanops.nanmax, func,
300-
allow_complex=False,
301298
allow_str=False, allow_obj=False)
302299

303300
def _argminmax_wrap(self, value, axis=None, func=None):
@@ -355,7 +352,6 @@ def test_nankurt(self):
355352

356353
def test_nanprod(self):
357354
self.check_funs(nanops.nanprod, np.prod,
358-
allow_complex=False,
359355
allow_str=False, allow_date=False)
360356

361357
def check_nancorr_nancov_2d(self, checkfun, targ0, targ1, **kwargs):

0 commit comments

Comments
 (0)