summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/arrayterator.py2
-rw-r--r--numpy/lib/format.py3
-rw-r--r--numpy/lib/function_base.py3
-rw-r--r--numpy/lib/index_tricks.py6
-rw-r--r--numpy/lib/npyio.py2
-rw-r--r--numpy/lib/polynomial.py2
-rw-r--r--numpy/lib/shape_base.py10
-rw-r--r--numpy/lib/type_check.py2
-rw-r--r--numpy/lib/utils.py4
9 files changed, 15 insertions, 19 deletions
diff --git a/numpy/lib/arrayterator.py b/numpy/lib/arrayterator.py
index 094d41c11..c2cde574e 100644
--- a/numpy/lib/arrayterator.py
+++ b/numpy/lib/arrayterator.py
@@ -188,7 +188,7 @@ class Arrayterator(object):
step = self.step[:]
ndims = len(self.var.shape)
- while 1:
+ while True:
count = self.buf_size or reduce(mul, self.shape)
# iterate over each dimension, looking for the
diff --git a/numpy/lib/format.py b/numpy/lib/format.py
index 40788e148..81e8cd010 100644
--- a/numpy/lib/format.py
+++ b/numpy/lib/format.py
@@ -344,8 +344,7 @@ def read_array_header_1_0(fp):
if not isinstance(d, dict):
msg = "Header is not a dictionary: %r"
raise ValueError(msg % d)
- keys = list(d.keys())
- keys.sort()
+ keys = sorted(d.keys())
if keys != ['descr', 'fortran_order', 'shape']:
msg = "Header does not contain the correct keys: %r"
raise ValueError(msg % (keys,))
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 1ead53c87..a7163a7ca 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -1273,8 +1273,7 @@ def unique(x):
idx = concatenate(([True],tmp[1:]!=tmp[:-1]))
return tmp[idx]
except AttributeError:
- items = list(set(x))
- items.sort()
+ items = sorted(set(x))
return asarray(items)
def extract(condition, arr):
diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py
index 314cba120..b3c9b72bc 100644
--- a/numpy/lib/index_tricks.py
+++ b/numpy/lib/index_tricks.py
@@ -244,7 +244,7 @@ class AxisConcatenator(object):
frame = sys._getframe().f_back
mymat = matrix.bmat(key,frame.f_globals,frame.f_locals)
return mymat
- if type(key) is not tuple:
+ if not isinstance(key, tuple):
key = (key,)
objs = []
scalars = []
@@ -252,7 +252,7 @@ class AxisConcatenator(object):
scalartypes = []
for k in range(len(key)):
scalar = False
- if type(key[k]) is slice:
+ if isinstance(key[k], slice):
step = key[k].step
start = key[k].start
stop = key[k].stop
@@ -627,7 +627,7 @@ class IndexExpression(object):
self.maketuple = maketuple
def __getitem__(self, item):
- if self.maketuple and type(item) != tuple:
+ if self.maketuple and not isinstance(item, tuple):
return (item,)
else:
return item
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index c13c7e94a..fbcb5a46e 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -1025,7 +1025,7 @@ def savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='',
if len(fmt) != ncol:
raise AttributeError('fmt has wrong shape. %s' % str(fmt))
format = asstr(delimiter).join(map(asstr, fmt))
- elif type(fmt) is str:
+ elif isinstance(fmt, str):
n_fmt_chars = fmt.count('%')
error = ValueError('fmt has wrong number of %% formats: %s' % fmt)
if n_fmt_chars == 1:
diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py
index e61a89b87..5402adc6d 100644
--- a/numpy/lib/polynomial.py
+++ b/numpy/lib/polynomial.py
@@ -905,7 +905,7 @@ def _raise_power(astr, wrap=70):
line1 = ''
line2 = ''
output = ' '
- while 1:
+ while True:
mat = _poly_mat.search(astr, n)
if mat is None:
break
diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py
index de8606167..5357c62df 100644
--- a/numpy/lib/shape_base.py
+++ b/numpy/lib/shape_base.py
@@ -643,10 +643,9 @@ def get_array_prepare(*args):
In case of ties, leftmost wins. If no wrapper is found, return None
"""
- wrappers = [(getattr(x, '__array_priority__', 0), -i,
+ wrappers = sorted((getattr(x, '__array_priority__', 0), -i,
x.__array_prepare__) for i, x in enumerate(args)
- if hasattr(x, '__array_prepare__')]
- wrappers.sort()
+ if hasattr(x, '__array_prepare__'))
if wrappers:
return wrappers[-1][-1]
return None
@@ -656,10 +655,9 @@ def get_array_wrap(*args):
In case of ties, leftmost wins. If no wrapper is found, return None
"""
- wrappers = [(getattr(x, '__array_priority__', 0), -i,
+ wrappers = sorted((getattr(x, '__array_priority__', 0), -i,
x.__array_wrap__) for i, x in enumerate(args)
- if hasattr(x, '__array_wrap__')]
- wrappers.sort()
+ if hasattr(x, '__array_wrap__'))
if wrappers:
return wrappers[-1][-1]
return None
diff --git a/numpy/lib/type_check.py b/numpy/lib/type_check.py
index 6e0cfcddb..cb9b6ee49 100644
--- a/numpy/lib/type_check.py
+++ b/numpy/lib/type_check.py
@@ -58,7 +58,7 @@ def mintypecode(typechars,typeset='GDFgdf',default='d'):
'G'
"""
- typecodes = [(type(t) is type('') and t) or asarray(t).dtype.char\
+ typecodes = [(isinstance(t, str) and t) or asarray(t).dtype.char\
for t in typechars]
intersection = [t for t in typecodes if t in typeset]
if not intersection:
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py
index 2519cd4d4..f94abeeab 100644
--- a/numpy/lib/utils.py
+++ b/numpy/lib/utils.py
@@ -435,7 +435,7 @@ def _makenamedict(module='numpy'):
thedict = {module.__name__:module.__dict__}
dictlist = [module.__name__]
totraverse = [module.__dict__]
- while 1:
+ while True:
if len(totraverse) == 0:
break
thisdict = totraverse.pop(0)
@@ -584,7 +584,7 @@ def info(object=None,maxwidth=76,output=sys.stdout,toplevel='numpy'):
methstr, other = pydoc.splitdoc(inspect.getdoc(thisobj) or "None")
print(" %s -- %s" % (meth, methstr), file=output)
- elif type(object) is types.InstanceType: ## check for __call__ method
+ elif isinstance(object, types.InstanceType): ## check for __call__ method
print("Instance of class: ", object.__class__.__name__, file=output)
print(file=output)
if hasattr(object, '__call__'):