Skip to content

Commit b7bc8d4

Browse files
committed
Skip NAs when aggregating with complex dtypes
1 parent d47f708 commit b7bc8d4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

xray/core/ops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ def f(values, axis=None, skipna=None, **kwargs):
292292
if coerce_strings and values.dtype.kind in 'SU':
293293
values = values.astype(object)
294294

295-
if skipna or (skipna is None and values.dtype.kind == 'f'):
296-
if values.dtype.kind not in ['i', 'f']:
295+
if skipna or (skipna is None and values.dtype.kind in 'cf'):
296+
if values.dtype.kind not in ['i', 'f', 'c']:
297297
raise NotImplementedError(
298298
'skipna=True not yet implemented for %s with dtype %s'
299299
% (name, values.dtype))

xray/test/test_variable.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,12 @@ def test_real_and_imag(self):
382382
expected_abs = self.cls('x', np.sqrt(2 * np.arange(3) ** 2))
383383
self.assertVariableAllClose(abs(v), expected_abs)
384384

385+
def test_aggregate_complex(self):
386+
# should skip NaNs
387+
v = self.cls('x', [1, 2j, np.nan])
388+
expected = Variable((), 0.5 + 1j)
389+
self.assertVariableAllClose(v.mean(), expected)
390+
385391

386392
class TestVariable(TestCase, VariableSubclassTestCases):
387393
cls = staticmethod(Variable)

0 commit comments

Comments
 (0)