Skip to content

Commit fb3af0c

Browse files
committed
keep all axes for all components
1 parent d5a5597 commit fb3af0c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

activestorage/active.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,9 @@ def _from_storage(self, stripped_indexer, drop_axes, out_shape, out_dtype,
392392
# cf-python needs the sample size for all reductions;
393393
# see the 'mtol' parameter of cf.Field.collapse.)
394394
#
395-
# Note that in this case the reduced data must always
396-
# have the same number of dimensions as the original
397-
# array, i.e. 'drop_axes' is always considered False,
395+
# Note that in all components must always have the
396+
# same number of dimensions as the original array,
397+
# i.e. 'drop_axes' is always considered False,
398398
# regardless of its setting. (Rationale: dask
399399
# reductions require the per-dask-chunk partial
400400
# reductions to retain these dimensions so that
@@ -404,20 +404,21 @@ def _from_storage(self, stripped_indexer, drop_axes, out_shape, out_dtype,
404404
n = np.reshape(n, shape1)
405405
out = out.reshape(shape1)
406406

407+
n = np.sum(counts).reshape(shape1)
407408
if self._method == "mean":
408409
# For the average, the returned component is
409410
# "sum", not "mean"
410-
out = {"sum": out, "n": sum(counts)}
411+
out = {"sum": out, "n": n}
411412
else:
412-
out = {self._method: out, "n": sum(counts)}
413+
out = {self._method: out, "n": n}
413414
else:
414415
# Return the reduced data as a numpy array. For most
415416
# methods the data is already in this form.
416417
if self._method == "mean":
417418
# For the average, it is actually the sum that has
418419
# been created, so we need to divide by the sample
419420
# size.
420-
out = out / sum(counts)
421+
out = out / np.sum(counts).reshape(shape1)
421422

422423
return out
423424

0 commit comments

Comments
 (0)