diff options
author | Julian Taylor <juliantaylor108@gmail.com> | 2014-03-29 00:33:12 +0100 |
---|---|---|
committer | Julian Taylor <juliantaylor108@gmail.com> | 2014-03-29 00:33:12 +0100 |
commit | 7b0d0754833468b960c9dd1c8b903ad30508eb70 (patch) | |
tree | ad2d12cf40b01919bf945c91c0548ad2b48757cc /numpy/ma/core.py | |
parent | 9fc98aed1473e73dc8bd97ca79728c400fcc3d37 (diff) | |
parent | 92a0a2c4e49474c0240da6be25680d488877109b (diff) | |
download | numpy-7b0d0754833468b960c9dd1c8b903ad30508eb70.tar.gz |
Merge pull request #4565 from charris/fill_value_fix
Raise TypeError when setting inappropriate ma fill_value
Diffstat (limited to 'numpy/ma/core.py')
-rw-r--r-- | numpy/ma/core.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index 9c3c6a615..faf9896a5 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -417,13 +417,18 @@ def _check_fill_value(fill_value, ndtype): dtype=ndtype) else: if isinstance(fill_value, basestring) and (ndtype.char not in 'OSVU'): - fill_value = default_fill_value(ndtype) + err_msg = "Cannot set fill value of string with array of dtype %s" + raise TypeError(err_msg % ndtype) else: - # In case we want to convert 1e+20 to int... + # In case we want to convert 1e20 to int... try: - fill_value = np.array(fill_value, copy=False, dtype=ndtype)#.item() + fill_value = np.array(fill_value, copy=False, dtype=ndtype) except OverflowError: - fill_value = default_fill_value(ndtype) + # Raise TypeError instead of OverflowError. OverflowError + # is seldom used, and the real problem here is that the + # passed fill_value is not compatible with the ndtype. + err_msg = "Fill value %s overflows dtype %s" + raise TypeError(err_msg % (fill_value, ndtype)) return np.array(fill_value) |