summaryrefslogtreecommitdiff
path: root/numpy/ma/core.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-10-04 23:35:42 -0700
committerGitHub <noreply@github.com>2017-10-04 23:35:42 -0700
commit98e7efc12ccbc53bef8b6c4e98354b29dcede3d0 (patch)
tree2514b5350585c9628929637380c078803895f322 /numpy/ma/core.py
parent729df78cfff15adb1a78377f18050e91f919a724 (diff)
parentaa7b339d6172775db71834677d68ec89da1aaf4e (diff)
downloadnumpy-98e7efc12ccbc53bef8b6c4e98354b29dcede3d0.tar.gz
Merge pull request #9817 from kenogo/master
BUG: Added exception for casting numpy.ma.masked to long
Diffstat (limited to 'numpy/ma/core.py')
-rw-r--r--numpy/ma/core.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 130817e7a..5f4d14a73 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):
"""