Skip to content

Commit 8775599

Browse files
committed
Skip NAs when aggregating with complex dtypes
1 parent e0de5c3 commit 8775599

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

xray/core/ops.py

+2-2
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

+6
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)