summaryrefslogtreecommitdiff
path: root/numpy/oldnumeric/ma.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-04-13 12:21:42 -0600
committerCharles Harris <charlesr.harris@gmail.com>2013-04-14 08:57:45 -0600
commitc879ad8a39f2b74edcdaa05a2f2f854fb235537d (patch)
tree378c562ff234193cc7391a0f89095b693f42a42e /numpy/oldnumeric/ma.py
parent3f2c789ffd0d2e05596b15ea6cd644262f96200e (diff)
downloadnumpy-c879ad8a39f2b74edcdaa05a2f2f854fb235537d.tar.gz
2to3: Apply types fixer.
Python 3 removes the builtin types from the types module. The types fixer replaces such references with the builtin types where possible and also takes care of some special cases: types.TypeNone <- type(None) types.NotImplementedType <- type(NotImplemented) types.EllipsisType <- type(Ellipsis) The only two tricky substitutions are types.StringType <- bytes types.LongType <- int These are fixed up to support both Python 3 and Python 2 code by importing the long and bytes types from numpy.compat. Closes #3240.
Diffstat (limited to 'numpy/oldnumeric/ma.py')
-rw-r--r--numpy/oldnumeric/ma.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/numpy/oldnumeric/ma.py b/numpy/oldnumeric/ma.py
index 3b861709e..fbc0aca27 100644
--- a/numpy/oldnumeric/ma.py
+++ b/numpy/oldnumeric/ma.py
@@ -18,10 +18,12 @@ from functools import reduce
import numpy.core.umath as umath
import numpy.core.fromnumeric as fromnumeric
+import numpy.core.numeric as numeric
from numpy.core.numeric import newaxis, ndarray, inf
from numpy.core.fromnumeric import amax, amin
from numpy.core.numerictypes import bool_, typecodes
import numpy.core.numeric as numeric
+from numpy.compat import bytes, long
if sys.version_info[0] >= 3:
_MAXINT = sys.maxsize
@@ -93,13 +95,13 @@ default_object_fill_value = '?'
def default_fill_value (obj):
"Function to calculate default fill value for an object."
- if isinstance(obj, types.FloatType):
+ if isinstance(obj, float):
return default_real_fill_value
- elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):
+ elif isinstance(obj, int) or isinstance(obj, long):
return default_integer_fill_value
- elif isinstance(obj, types.StringType):
+ elif isinstance(obj, bytes):
return default_character_fill_value
- elif isinstance(obj, types.ComplexType):
+ elif isinstance(obj, complex):
return default_complex_fill_value
elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):
x = obj.dtype.char
@@ -119,9 +121,9 @@ def default_fill_value (obj):
def minimum_fill_value (obj):
"Function to calculate default fill value suitable for taking minima."
- if isinstance(obj, types.FloatType):
+ if isinstance(obj, float):
return numeric.inf
- elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):
+ elif isinstance(obj, int) or isinstance(obj, long):
return _MAXINT
elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):
x = obj.dtype.char
@@ -136,9 +138,9 @@ def minimum_fill_value (obj):
def maximum_fill_value (obj):
"Function to calculate default fill value suitable for taking maxima."
- if isinstance(obj, types.FloatType):
+ if isinstance(obj, float):
return -inf
- elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):
+ elif isinstance(obj, int) or isinstance(obj, long):
return -_MAXINT
elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):
x = obj.dtype.char
@@ -239,7 +241,7 @@ def filled (a, value = None):
return a.filled(value)
elif isinstance(a, ndarray) and a.flags['CONTIGUOUS']:
return a
- elif isinstance(a, types.DictType):
+ elif isinstance(a, dict):
return numeric.array(a, 'O')
else:
return numeric.array(a)
@@ -1543,7 +1545,7 @@ def new_repeat(a, repeats, axis=None):
telling how many times to repeat each element.
"""
af = filled(a)
- if isinstance(repeats, types.IntType):
+ if isinstance(repeats, int):
if axis is None:
num = af.size
else:
@@ -2153,10 +2155,9 @@ def asarray(data, dtype=None):
# Add methods to support ndarray interface
# XXX: I is better to to change the masked_*_operation adaptors
# XXX: to wrap ndarray methods directly to create ma.array methods.
-from types import MethodType
def _m(f):
- return MethodType(f, None, array)
+ return types.MethodType(f, None, array)
def not_implemented(*args, **kwds):
raise NotImplementedError("not yet implemented for numpy.ma arrays")
@@ -2280,7 +2281,7 @@ array.std = _m(_std)
array.view = _m(not_implemented)
array.round = _m(around)
-del _m, MethodType, not_implemented
+del _m, not_implemented
masked = MaskedArray(0, int, mask=1)