diff options
author | Keno Goertz <keno@goertz-berlin.com> | 2017-10-05 01:17:14 +0200 |
---|---|---|
committer | Keno Goertz <keno@goertz-berlin.com> | 2017-10-05 01:18:42 +0200 |
commit | aa7b339d6172775db71834677d68ec89da1aaf4e (patch) | |
tree | 43828f7f72bc81047592be6e526d60394d209d46 /numpy/ma/core.py | |
parent | 1f4ed32fdf0cf2f197d9a8da5698580ed6ec7683 (diff) | |
download | numpy-aa7b339d6172775db71834677d68ec89da1aaf4e.tar.gz |
BUG: Added exception for casting numpy.ma.masked to long
TST: Added test_coercion_long and removed knownfailure from test_coercion_int
Diffstat (limited to 'numpy/ma/core.py')
-rw-r--r-- | numpy/ma/core.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index b6e2edf5a..e4118e5dc 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -4230,6 +4230,18 @@ class MaskedArray(ndarray): elif self._mask: raise MaskError('Cannot convert masked element to a Python int.') return int(self.item()) + + def __long__(self): + """ + Convert to long. + """ + if self.size > 1: + raise TypeError("Only length-1 arrays can be conveted " + "to Python scalars") + elif self._mask: + raise MaskError('Cannot convert masked element to a Python long.') + return long(self.item()) + def get_imag(self): """ |