summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2014-07-30 16:48:11 -0600
committerJulian Taylor <jtaylor.debian@googlemail.com>2014-07-31 21:21:13 +0200
commitdec6658cdc10a23ad0e733fb52a814306033d88c (patch)
treedfa2a5d879f9ec10f75287a045070729cf415432 /numpy/lib
parent0b5a6645ee110a8d4c6b5defd8c01791ee48bda1 (diff)
downloadnumpy-dec6658cdc10a23ad0e733fb52a814306033d88c.tar.gz
MAINT: Fixes for problems in numpy/lib revealed by pyflakes.
Some of those problems look like potential coding errors. In those cases a Fixme comment was made and the offending code, usually an unused variable, was commented out.
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/_datasource.py9
-rw-r--r--numpy/lib/_iotools.py2
-rw-r--r--numpy/lib/arraypad.py5
-rw-r--r--numpy/lib/arraysetops.py11
-rw-r--r--numpy/lib/arrayterator.py1
-rw-r--r--numpy/lib/financial.py6
-rw-r--r--numpy/lib/function_base.py29
-rw-r--r--numpy/lib/nanfunctions.py2
-rw-r--r--numpy/lib/npyio.py6
-rw-r--r--numpy/lib/recfunctions.py21
-rw-r--r--numpy/lib/shape_base.py19
-rw-r--r--numpy/lib/twodim_base.py16
-rw-r--r--numpy/lib/user_array.py4
-rw-r--r--numpy/lib/utils.py8
14 files changed, 66 insertions, 73 deletions
diff --git a/numpy/lib/_datasource.py b/numpy/lib/_datasource.py
index 96d9af905..495bec49e 100644
--- a/numpy/lib/_datasource.py
+++ b/numpy/lib/_datasource.py
@@ -33,14 +33,13 @@ Example::
"""
from __future__ import division, absolute_import, print_function
-__docformat__ = "restructuredtext en"
-
import os
import sys
-from shutil import rmtree, copyfile, copyfileobj
+import shutil
_open = open
+
# Using a class instead of a module-level dictionary
# to reduce the inital 'import numpy' overhead by
# deferring the import of bz2 and gzip until needed
@@ -209,7 +208,7 @@ class DataSource (object):
def __del__(self):
# Remove temp directories
if self._istmpdest:
- rmtree(self._destpath)
+ shutil.rmtree(self._destpath)
def _iszip(self, filename):
"""Test if the filename is a zip file by looking at the file extension.
@@ -294,7 +293,7 @@ class DataSource (object):
openedurl = urlopen(path)
f = _open(upath, 'wb')
try:
- copyfileobj(openedurl, f)
+ shutil.copyfileobj(openedurl, f)
finally:
f.close()
openedurl.close()
diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py
index aa39e25a1..f54f2196c 100644
--- a/numpy/lib/_iotools.py
+++ b/numpy/lib/_iotools.py
@@ -8,7 +8,7 @@ __docformat__ = "restructuredtext en"
import sys
import numpy as np
import numpy.core.numeric as nx
-from numpy.compat import asbytes, bytes, asbytes_nested, long, basestring
+from numpy.compat import asbytes, bytes, asbytes_nested, basestring
if sys.version_info[0] >= 3:
from builtins import bool, int, float, complex, object, str
diff --git a/numpy/lib/arraypad.py b/numpy/lib/arraypad.py
index 82f741df9..befa9839e 100644
--- a/numpy/lib/arraypad.py
+++ b/numpy/lib/arraypad.py
@@ -8,6 +8,7 @@ from __future__ import division, absolute_import, print_function
import numpy as np
from numpy.compat import long
+
__all__ = ['pad']
@@ -1419,7 +1420,6 @@ def pad(array, pad_width, mode=None, **kwargs):
method = kwargs['reflect_type']
safe_pad = newmat.shape[axis] - 1
- repeat = safe_pad
while ((pad_before > safe_pad) or (pad_after > safe_pad)):
offset = 0
pad_iter_b = min(safe_pad,
@@ -1443,7 +1443,6 @@ def pad(array, pad_width, mode=None, **kwargs):
# length, to keep the period of the reflections consistent.
method = kwargs['reflect_type']
safe_pad = newmat.shape[axis]
- repeat = safe_pad
while ((pad_before > safe_pad) or
(pad_after > safe_pad)):
pad_iter_b = min(safe_pad,
@@ -1462,7 +1461,6 @@ def pad(array, pad_width, mode=None, **kwargs):
# for indexing tricks. We can only safely pad the original axis
# length, to keep the period of the reflections consistent.
safe_pad = newmat.shape[axis]
- repeat = safe_pad
while ((pad_before > safe_pad) or
(pad_after > safe_pad)):
pad_iter_b = min(safe_pad,
@@ -1473,7 +1471,6 @@ def pad(array, pad_width, mode=None, **kwargs):
pad_before -= pad_iter_b
pad_after -= pad_iter_a
safe_pad += pad_iter_b + pad_iter_a
-
newmat = _pad_wrap(newmat, (pad_before, pad_after), axis)
return newmat
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py
index 005703d16..42555d30f 100644
--- a/numpy/lib/arraysetops.py
+++ b/numpy/lib/arraysetops.py
@@ -26,11 +26,14 @@ To do: Optionally return indices analogously to unique for all functions.
"""
from __future__ import division, absolute_import, print_function
-__all__ = ['ediff1d', 'intersect1d', 'setxor1d', 'union1d', 'setdiff1d',
- 'unique', 'in1d']
-
import numpy as np
-from numpy.lib.utils import deprecate
+
+
+__all__ = [
+ 'ediff1d', 'intersect1d', 'setxor1d', 'union1d', 'setdiff1d', 'unique',
+ 'in1d'
+ ]
+
def ediff1d(ary, to_end=None, to_begin=None):
"""
diff --git a/numpy/lib/arrayterator.py b/numpy/lib/arrayterator.py
index c2cde574e..8ac720ccd 100644
--- a/numpy/lib/arrayterator.py
+++ b/numpy/lib/arrayterator.py
@@ -9,7 +9,6 @@ a user-specified number of elements.
"""
from __future__ import division, absolute_import, print_function
-import sys
from operator import mul
from functools import reduce
diff --git a/numpy/lib/financial.py b/numpy/lib/financial.py
index c085a5d53..e54614483 100644
--- a/numpy/lib/financial.py
+++ b/numpy/lib/financial.py
@@ -718,7 +718,6 @@ def mirr(values, finance_rate, reinvest_rate):
Modified internal rate of return
"""
-
values = np.asarray(values, dtype=np.double)
n = values.size
pos = values > 0
@@ -728,8 +727,3 @@ def mirr(values, finance_rate, reinvest_rate):
numer = np.abs(npv(reinvest_rate, values*pos))
denom = np.abs(npv(finance_rate, values*neg))
return (numer/denom)**(1.0/(n - 1))*(1 + reinvest_rate) - 1
-
-if __name__ == '__main__':
- import doctest
- import numpy as np
- doctest.testmod(verbose=True)
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 00bfab6ba..3d8ffc586 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -1,15 +1,5 @@
from __future__ import division, absolute_import, print_function
-__docformat__ = "restructuredtext en"
-__all__ = [
- 'select', 'piecewise', 'trim_zeros', 'copy', 'iterable', 'percentile',
- 'diff', 'gradient', 'angle', 'unwrap', 'sort_complex', 'disp',
- 'extract', 'place', 'vectorize', 'asarray_chkfinite', 'average',
- 'histogram', 'histogramdd', 'bincount', 'digitize', 'cov', 'corrcoef',
- 'msort', 'median', 'sinc', 'hamming', 'hanning', 'bartlett',
- 'blackman', 'kaiser', 'trapz', 'i0', 'add_newdoc', 'add_docstring',
- 'meshgrid', 'delete', 'insert', 'append', 'interp', 'add_newdoc_ufunc']
-
import warnings
import sys
import collections
@@ -20,21 +10,21 @@ import numpy.core.numeric as _nx
from numpy.core import linspace, atleast_1d, atleast_2d
from numpy.core.numeric import (
ones, zeros, arange, concatenate, array, asarray, asanyarray, empty,
- empty_like, ndarray, around, floor, ceil, take, ScalarType, dot, where,
- intp, integer, isscalar
+ empty_like, ndarray, around, floor, ceil, take, dot, where, intp,
+ integer, isscalar
)
from numpy.core.umath import (
pi, multiply, add, arctan2, frompyfunc, cos, less_equal, sqrt, sin,
mod, exp, log10
)
from numpy.core.fromnumeric import (
- ravel, nonzero, choose, sort, partition, mean
+ ravel, nonzero, sort, partition, mean
)
from numpy.core.numerictypes import typecodes, number
from numpy.lib.twodim_base import diag
+from .utils import deprecate
from ._compiled_base import _insert, add_docstring
from ._compiled_base import digitize, bincount, interp as compiled_interp
-from .utils import deprecate
from ._compiled_base import add_newdoc_ufunc
from numpy.compat import long
@@ -43,6 +33,17 @@ if sys.version_info[0] < 3:
range = xrange
+__all__ = [
+ 'select', 'piecewise', 'trim_zeros', 'copy', 'iterable', 'percentile',
+ 'diff', 'gradient', 'angle', 'unwrap', 'sort_complex', 'disp',
+ 'extract', 'place', 'vectorize', 'asarray_chkfinite', 'average',
+ 'histogram', 'histogramdd', 'bincount', 'digitize', 'cov', 'corrcoef',
+ 'msort', 'median', 'sinc', 'hamming', 'hanning', 'bartlett',
+ 'blackman', 'kaiser', 'trapz', 'i0', 'add_newdoc', 'add_docstring',
+ 'meshgrid', 'delete', 'insert', 'append', 'interp', 'add_newdoc_ufunc'
+ ]
+
+
def iterable(y):
"""
Check whether or not an object can be iterated over.
diff --git a/numpy/lib/nanfunctions.py b/numpy/lib/nanfunctions.py
index 7120760b5..f5ac35e54 100644
--- a/numpy/lib/nanfunctions.py
+++ b/numpy/lib/nanfunctions.py
@@ -17,9 +17,7 @@ Functions
from __future__ import division, absolute_import, print_function
import warnings
-import operator
import numpy as np
-from numpy.core.fromnumeric import partition
from numpy.lib.function_base import _ureduce as _ureduce
__all__ = [
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index c1813512a..479e9c099 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -33,7 +33,8 @@ loads = pickle.loads
__all__ = [
'savetxt', 'loadtxt', 'genfromtxt', 'ndfromtxt', 'mafromtxt',
'recfromtxt', 'recfromcsv', 'load', 'loads', 'save', 'savez',
- 'savez_compressed', 'packbits', 'unpackbits', 'fromregex', 'DataSource']
+ 'savez_compressed', 'packbits', 'unpackbits', 'fromregex', 'DataSource'
+ ]
def seek_gzip_factory(f):
@@ -1596,7 +1597,8 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
# Make sure we have the corrected keys in user_converters...
user_converters.update(uc_update)
- miss_chars = [_.missing_values for _ in converters]
+ # Fixme: possible error as following variable never used.
+ #miss_chars = [_.missing_values for _ in converters]
# Initialize the output lists ...
# ... rows
diff --git a/numpy/lib/recfunctions.py b/numpy/lib/recfunctions.py
index ae4ee56c6..6ae8b8445 100644
--- a/numpy/lib/recfunctions.py
+++ b/numpy/lib/recfunctions.py
@@ -22,16 +22,13 @@ if sys.version_info[0] < 3:
_check_fill_value = np.ma.core._check_fill_value
-__all__ = ['append_fields',
- 'drop_fields',
- 'find_duplicates',
- 'get_fieldstructure',
- 'join_by',
- 'merge_arrays',
- 'rec_append_fields', 'rec_drop_fields', 'rec_join',
- 'recursive_fill_fields', 'rename_fields',
- 'stack_arrays',
- ]
+
+__all__ = [
+ 'append_fields', 'drop_fields', 'find_duplicates',
+ 'get_fieldstructure', 'join_by', 'merge_arrays',
+ 'rec_append_fields', 'rec_drop_fields', 'rec_join',
+ 'recursive_fill_fields', 'rename_fields', 'stack_arrays',
+ ]
def recursive_fill_fields(input, output):
@@ -896,7 +893,9 @@ def join_by(key, r1, r2, jointype='inner', r1postfix='1', r2postfix='2',
# Make sure we work with ravelled arrays
r1 = r1.ravel()
r2 = r2.ravel()
- (nb1, nb2) = (len(r1), len(r2))
+ # Fixme: nb2 below is never used. Commenting out for pyflakes.
+ # (nb1, nb2) = (len(r1), len(r2))
+ nb1 = len(r1)
(r1names, r2names) = (r1.dtype.names, r2.dtype.names)
# Check the names for collision
diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py
index a6d391728..929646de6 100644
--- a/numpy/lib/shape_base.py
+++ b/numpy/lib/shape_base.py
@@ -1,16 +1,21 @@
from __future__ import division, absolute_import, print_function
-__all__ = ['column_stack', 'row_stack', 'dstack', 'array_split', 'split', 'hsplit',
- 'vsplit', 'dsplit', 'apply_over_axes', 'expand_dims',
- 'apply_along_axis', 'kron', 'tile', 'get_array_wrap']
-
import warnings
import numpy.core.numeric as _nx
-from numpy.core.numeric import asarray, zeros, newaxis, outer, \
- concatenate, isscalar, array, asanyarray
+from numpy.core.numeric import (
+ asarray, zeros, outer, concatenate, isscalar, array, asanyarray
+ )
from numpy.core.fromnumeric import product, reshape
-from numpy.core import hstack, vstack, atleast_3d
+from numpy.core import vstack, atleast_3d
+
+
+__all__ = [
+ 'column_stack', 'row_stack', 'dstack', 'array_split', 'split',
+ 'hsplit', 'vsplit', 'dsplit', 'apply_over_axes', 'expand_dims',
+ 'apply_along_axis', 'kron', 'tile', 'get_array_wrap'
+ ]
+
def apply_along_axis(func1d, axis, arr, *args, **kwargs):
"""
diff --git a/numpy/lib/twodim_base.py b/numpy/lib/twodim_base.py
index a8925592a..2861e1c4a 100644
--- a/numpy/lib/twodim_base.py
+++ b/numpy/lib/twodim_base.py
@@ -3,19 +3,19 @@
"""
from __future__ import division, absolute_import, print_function
-__all__ = ['diag', 'diagflat', 'eye', 'fliplr', 'flipud', 'rot90', 'tri',
- 'triu', 'tril', 'vander', 'histogram2d', 'mask_indices',
- 'tril_indices', 'tril_indices_from', 'triu_indices',
- 'triu_indices_from',
- ]
-
from numpy.core.numeric import (
- asanyarray, subtract, arange, zeros, greater_equal, multiply, ones,
- asarray, where, less, int8, int16, int32, int64, empty, promote_types
+ asanyarray, arange, zeros, greater_equal, multiply, ones, asarray,
+ where, int8, int16, int32, int64, empty, promote_types
)
from numpy.core import iinfo
+__all__ = [
+ 'diag', 'diagflat', 'eye', 'fliplr', 'flipud', 'rot90', 'tri', 'triu',
+ 'tril', 'vander', 'histogram2d', 'mask_indices', 'tril_indices',
+ 'tril_indices_from', 'triu_indices', 'triu_indices_from', ]
+
+
i1 = iinfo(int8)
i2 = iinfo(int16)
i4 = iinfo(int32)
diff --git a/numpy/lib/user_array.py b/numpy/lib/user_array.py
index f62f6db59..3dde538d8 100644
--- a/numpy/lib/user_array.py
+++ b/numpy/lib/user_array.py
@@ -141,12 +141,8 @@ class container(object):
bitwise_or(self.array, other, self.array)
return self
- def __neg__(self):
- return self._rc(-self.array)
def __pos__(self):
return self._rc(self.array)
- def __abs__(self):
- return self._rc(abs(self.array))
def __invert__(self):
return self._rc(invert(self.array))
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py
index 6d41e8eb4..17c5b9743 100644
--- a/numpy/lib/utils.py
+++ b/numpy/lib/utils.py
@@ -6,13 +6,13 @@ import types
import re
from numpy.core.numerictypes import issubclass_, issubsctype, issubdtype
-from numpy.core import product, ndarray, ufunc, asarray
+from numpy.core import ndarray, ufunc, asarray
__all__ = [
'issubclass_', 'issubsctype', 'issubdtype', 'deprecate',
'deprecate_with_doc', 'get_include', 'info', 'source', 'who',
'lookfor', 'byte_bounds', 'safe_eval'
-]
+ ]
def get_include():
"""
@@ -1134,11 +1134,11 @@ def safe_eval(source):
walker = SafeEval()
try:
ast = compiler.parse(source, mode="eval")
- except SyntaxError as err:
+ except SyntaxError:
raise
try:
return walker.visit(ast)
- except SyntaxError as err:
+ except SyntaxError:
raise
#-----------------------------------------------------------------------------