You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When Data.stats is applied to an array with a non-trivial mask (i.e. having at least one masked element), with bothall=True and weights=0 set (for zero or Falsy weights arguments only, even though that doesn't really make sense to specify for any useful purpose but should regardless be handled elegantly in case someone tries it or ends up with that), it returns an obscure AttributeError, whereas with only one of those keywords set, or a non-masked array, it handles everything as it should, as shown in the snippet below.
This is an edge case which will probably not give any useful result due to the zero weighting for everything, but we should catch the error and give a more useful one regardless.
>>> import cf
>>> d = cf.Data([0, 1, 2], mask=[0, 1, 0])
>>> d.stats(all=True, weights=0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/sadie/cf-python/cf/data/data.py", line 9771, in stats
return {op: val.array.item() for op, val in data_values.items()}
File "/home/sadie/cf-python/cf/data/data.py", line 9771, in <dictcomp>
return {op: val.array.item() for op, val in data_values.items()}
File "/home/sadie/cf-python/cf/data/data.py", line 4688, in array
array = self.compute().copy()
File "/home/sadie/cf-python/cf/data/data.py", line 2368, in compute
a.harden_mask()
File "/home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/numpy/ma/core.py", line 3556, in harden_mask
self._hardmask = True
File "/home/sadie/anaconda3/envs/cf-env/lib/python3.8/site-packages/numpy/ma/core.py", line 6540, in __setattr__
raise AttributeError(
AttributeError: attributes of masked are not writeable
>>> # But note that:
>>> d.stats(all=True)
{'minimum': 0, 'mean': 1.0, 'median': 1.0, 'maximum': 2, 'range': 2, 'mid_range': 1.0, 'standard_deviation': 1.0, 'root_mean_square': 1.4142135623730951, 'minimum_absolute_value': 0, 'maximum_absolute_value': 2, 'mean_absolute_value': 1.0, 'mean_of_upper_decile': 2.0, 'sum': 2, 'sum_of_squares': 4, 'variance': 1.0, 'sample_size': 2}
>>> d.stats(weights=0)
{'minimum': 0, 'mean': nan, 'median': 1.0, 'maximum': 2, 'range': 2, 'mid_range': 1.0, 'standard_deviation': 0.0, 'root_mean_square': nan, 'sample_size': 2}
>>> d.stats(all=True, weights=1)
{'minimum': 0, 'mean': 1.0, 'median': 1.0, 'maximum': 2, 'range': 2, 'mid_range': 1.0, 'standard_deviation': 1.0, 'root_mean_square': 1.4142135623730951, 'minimum_absolute_value': 0, 'maximum_absolute_value': 2, 'mean_absolute_value': 1.0, 'mean_of_upper_decile': 2.0, 'sum': 2, 'sum_of_squares': 4, 'variance': 1.0, 'sample_size': 2}
>>> # etc.
When
Data.stats
is applied to an array with a non-trivial mask (i.e. having at least one masked element), with bothall=True
andweights=0
set (for zero or Falsyweights
arguments only, even though that doesn't really make sense to specify for any useful purpose but should regardless be handled elegantly in case someone tries it or ends up with that), it returns an obscureAttributeError
, whereas with only one of those keywords set, or a non-masked array, it handles everything as it should, as shown in the snippet below.This is an edge case which will probably not give any useful result due to the zero weighting for everything, but we should catch the error and give a more useful one regardless.
Environment
Snippet shown used:
The text was updated successfully, but these errors were encountered: