@@ -1129,17 +1129,8 @@ def my_propagate(uncertainty, data, mask, **kwargs):
11291129
11301130 # Reshape array so odd dimensions represent pixels to be binned
11311131 # then apply function over those axes.
1132- m = None if (self .mask is None or self .mask is False or operation_ignores_mask ) else self .mask
1133- data = self .data
1134- if m is not None :
1135- for array_type , masked_type in ARRAY_MASK_MAP .items ():
1136- if isinstance (self .data , array_type ):
1137- break
1138- else :
1139- masked_type = np .ma .masked_array
1140- warn_user ("data and mask arrays of different or unrecognized types. Casting them into a numpy masked array." )
1141- data = masked_type (self .data , m )
1142-
1132+ data , sanitized_mask = _create_masked_array_for_rebinning (self .data , self .mask ,
1133+ operation_ignores_mask )
11431134 reshape = np .empty (len (data_shape ) + len (bin_shape ), dtype = int )
11441135 new_shape = (data_shape / bin_shape ).astype (int )
11451136 reshape [0 ::2 ] = new_shape
@@ -1192,7 +1183,7 @@ def my_propagate(uncertainty, data, mask, **kwargs):
11921183 flat_uncertainty = np .moveaxis (reshaped_uncertainty , dummy_axes , tuple (range (naxes )))
11931184 flat_uncertainty = flat_uncertainty .reshape (flat_shape )
11941185 flat_uncertainty = type (self .uncertainty )(flat_uncertainty )
1195- if m is not None :
1186+ if sanitized_mask is not None :
11961187 reshaped_mask = self .mask .reshape (tuple (reshape ))
11971188 flat_mask = np .moveaxis (reshaped_mask , dummy_axes , tuple (range (naxes )))
11981189 flat_mask = flat_mask .reshape (flat_shape )
@@ -1255,3 +1246,17 @@ def squeeze(self, axis=None):
12551246 if (item == 0 ).all ():
12561247 raise ValueError ("All axes are of length 1, therefore we will not squeeze NDCube to become a scalar. Use `axis=` keyword to specify a subset of axes to squeeze." )
12571248 return self [tuple (item )]
1249+
1250+
1251+ def _create_masked_array_for_rebinning (data , mask , operation_ignores_mask ):
1252+ m = None if (mask is None or mask is False or operation_ignores_mask ) else mask
1253+ if m is None :
1254+ return data , m
1255+ else :
1256+ for array_type , masked_type in ARRAY_MASK_MAP .items ():
1257+ if isinstance (data , array_type ):
1258+ break
1259+ else :
1260+ masked_type = np .ma .masked_array
1261+ warn_user ("data and mask arrays of different or unrecognized types. Casting them into a numpy masked array." )
1262+ return masked_type (data , m ), m
0 commit comments