Skip to content

Commit 586e317

Browse files
toddrjenjreback
authored andcommitted
make nanops work when ndim==1 and axis==0 ( issue #7354 )
1 parent 756f241 commit 586e317

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

doc/source/v0.14.1.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ Bug Fixes
215215
- Bug in ``quantile`` ignoring the axis keyword argument (:issue`7306`)
216216
- Bug where ``nanops._maybe_null_out`` doesn't work with complex numbers
217217
(:issue:`7353`)
218+
- Bug in several ``nanops`` functions when ``axis==0`` for
219+
1-dimensional ``nan`` arrays (:issue:`7354`)
218220

219221

220222

pandas/core/nanops.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def nanmean(values, axis=None, skipna=True):
260260
the_sum = _ensure_numeric(values.sum(axis, dtype=dtype_max))
261261
count = _get_counts(mask, axis)
262262

263-
if axis is not None:
263+
if axis is not None and getattr(the_sum, 'ndim', False):
264264
the_mean = the_sum / count
265265
ct_mask = count == 0
266266
if ct_mask.any():
@@ -517,7 +517,7 @@ def nanprod(values, axis=None, skipna=True):
517517

518518
def _maybe_arg_null_out(result, axis, mask, skipna):
519519
# helper function for nanargmin/nanargmax
520-
if axis is None:
520+
if axis is None or not getattr(result, 'ndim', False):
521521
if skipna:
522522
if mask.all():
523523
result = -1
@@ -544,7 +544,7 @@ def _get_counts(mask, axis):
544544

545545

546546
def _maybe_null_out(result, axis, mask):
547-
if axis is not None:
547+
if axis is not None and getattr(result, 'ndim', False):
548548
null_mask = (mask.shape[axis] - mask.sum(axis)) == 0
549549
if null_mask.any():
550550
if np.iscomplexobj(result):

pandas/tests/test_nanops.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def check_fun_data(self, testfunc, targfunc,
145145
'kwargs: %s' % kwargs)
146146
raise
147147

148-
if testarval.ndim <= 2:
148+
if testarval.ndim <= 1:
149149
return
150150

151151
try:
@@ -245,7 +245,7 @@ def _nanmean_wrap(self, value, *args, **kwargs):
245245
dtype = value.dtype
246246
res = nanops.nanmean(value, *args, **kwargs)
247247
if dtype.kind == 'O':
248-
res = np.round(res, decimals=15)
248+
res = np.round(res, decimals=13)
249249
return res
250250

251251
def _mean_wrap(self, value, *args, **kwargs):
@@ -254,7 +254,7 @@ def _mean_wrap(self, value, *args, **kwargs):
254254
value = value.astype('c16')
255255
res = np.mean(value, *args, **kwargs)
256256
if dtype.kind == 'O':
257-
res = np.round(res, decimals=15)
257+
res = np.round(res, decimals=13)
258258
return res
259259

260260
def test_nanmean(self):

0 commit comments

Comments
 (0)