8000 MAINT: Fix some pyflakes warnings in numpy/core/*.py · njsmith/numpy@7fa8ab6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7fa8ab6

Browse files
committed
MAINT: Fix some pyflakes warnings in numpy/core/*.py
These fixes are not agressive as some of the code is complicated and it is better to be careful. The files numeric.py and numerictypes.py are not easily analysed and the latter is self modifying. Pyflakes generates a number of invalid warnings for those files.
1 parent 8b3e9ae commit 7fa8ab6

File tree

9 files changed

+64
-75
lines changed

9 files changed

+64
-75
lines changed

numpy/core/_internal.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
import re
1010
import sys
11-
import warnings
1211

13-
from numpy.compat import asbytes, bytes, basestring
12+
from numpy.compat import asbytes, basestring
1413
from .multiarray import dtype, array, ndarray
1514
import ctypes
1615
from .numerictypes import object_
@@ -561,7 +560,6 @@ def _dtype_from_pep3118(spec, byteorder='@', is_subdtype=False):
561560
this_explicit_name = False
562561
common_alignment = 1
563562
is_padding = False
564-
last_offset = 0
565563

566564
dummy_name_index = [0]
567565

@@ -691,7 +689,6 @@ def get_dummy_name():
691689
raise RuntimeError("Duplicate field name '%s' in PEP3118 format"
692690
% name)
693691
fields[name] = (value, offset)
694-
last_offset = offset
695692
if not this_explicit_name:
696693
next_dummy_name()
697694

numpy/core/defchararray.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@
2525
from numpy.compat import asbytes, long
2626
import numpy
2727

28-
__all__ = ['chararray',
29-
'equal', 'not_equal', 'greater_equal', 'less_equal', 'greater', 'less',
30-
'str_len', 'add', 'multiply', 'mod', 'capitalize', 'center', 'count',
31-
'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format',
32-
'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace',
33-
'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip',
34-
'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition',
35-
'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip',
36-
'swapcase', 'title', 'translate', 'upper', 'zfill',
37-
'isnumeric', 'isdecimal',
38-
'array', 'asarray']
28+
__all__ = [
29+
'chararray', 'equal', 'not_equal', 'greater_equal', 'less_equal',
30+
'greater', 'less', 'str_len', 'add', 'multiply', 'mod', 'capitalize',
31+
'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs',
32+
'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace',
33+
'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition',
34+
'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit',
35+
'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase',
36+
'title', 'translate', 'upper', 'zfill', 'isnumeric', 'isdecimal',
37+
'array', 'asarray'
38+
]
39+
3940

4041
_globalvar = 0
4142
if sys.version_info[0] >= 3:

numpy/core/function_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
__all__ = ['logspace', 'linspace']
44

55
from . import numeric as _nx
6-
from .numeric import array, result_type, NaN
6+
from .numeric import result_type, NaN
77

88

99
def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None):

numpy/core/memmap.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
from __future__ import division, absolute_import, print_function
22

3-
__all__ = ['memmap']
4-
5-
import warnings
6-
import sys
7-
83
import numpy as np
94
from .numeric import uint8, ndarray, dtype
105
from numpy.compat import long, basestring
116

7+
__all__ = ['memmap']
8+
129
dtypedescr = dtype
1310
valid_filemodes = ["r", "c", "r+", "w+"]
1411
writeable_filemodes = ["r+", "w+"]

numpy/core/numeric.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import division, absolute_import, print_function
22

3-
import os
43
import sys
54
import warnings
65
import collections
@@ -21,30 +20,28 @@
2120
loads = pickle.loads
2221

2322

24-
__all__ = ['newaxis', 'ndarray', 'flatiter', 'nditer', 'nested_iters', 'ufunc',
25-
'arange', 'array', 'zeros', 'count_nonzero',
26-
'empty', 'broadcast', 'dtype', 'fromstring', 'fromfile',
27-
'frombuffer', 'int_asbuffer', 'where', 'argwhere', 'copyto',
28-
'concatenate', 'fastCopyAndTranspose', 'lexsort', 'set_numeric_ops',
29-
'can_cast', 'promote_types', 'min_scalar_type', 'result_type',
30-
'asarray', 'asanyarray', 'ascontiguousarray', 'asfortranarray',
31-
'isfortran', 'empty_like', 'zeros_like', 'ones_like',
32-
'correlate', 'convolve', 'inner', 'dot', 'einsum', 'outer', 'vdot',
33-
'alterdot', 'restoredot', 'roll', 'rollaxis', 'cross', 'tensordot',
34-
'array2string', 'get_printoptions', 'set_printoptions',
35-
'array_repr', 'array_str', 'set_string_function',
36-
'little_endian', 'require',
37-
'fromiter', 'array_equal', 'array_equiv',
38-
'indices', 'fromfunction', 'isclose',
39-
'load', 'loads', 'isscalar', 'binary_repr', 'base_repr',
40-
'ones', 'identity', 'allclose', 'compare_chararrays', 'putmask',
41-
'seterr', 'geterr', 'setbufsize', 'getbufsize',
42-
'seterrcall', 'geterrcall', 'errstate', 'flatnonzero',
43-
'Inf', 'inf', 'infty', 'Infinity',
44-
'nan', 'NaN', 'False_', 'True_', 'bitwise_not',
45-
'CLIP', 'RAISE', 'WRAP', 'MAXDIMS', 'BUFSIZE', 'ALLOW_THREADS',
46-
'ComplexWarning', 'may_share_memory', 'full', 'full_like',
47-
'matmul']
23+
__all__ = [
24+
'newaxis', 'ndarray', 'flatiter', 'nditer', 'nested_iters', 'ufunc',
25+
'arange', 'array', 'zeros', 'count_nonzero', 'empty', 'broadcast',
26+
'dtype', 'fromstring', 'fromfile', 'frombuffer', 'int_asbuffer',
27+
'where', 'argwhere', 'copyto', 'concatenate', 'fastCopyAndTranspose',
28+
'lexsort', 'set_numeric_ops', 'can_cast', 'promote_types',
29+
'min_scalar_type', 'result_type', 'asarray', 'asanyarray',
30+
'ascontiguousarray', 'asfortranarray', 'isfortran', 'empty_like',
31+
'zeros_like', 'ones_like', 'correlate', 'convolve', 'inner', 'dot',
32+
'einsum', 'outer', 'vdot', 'alterdot', 'restoredot', 'roll',
33+
'rollaxis', 'cross', 'tensordot', 'array2string', 'get_printoptions',
34+
'set_printoptions', 'array_repr', 'array_str', 'set_string_function',
35+
'little_endian', 'require', 'fromiter', 'array_equal', 'array_equiv',
36+
'indices', 'fromfunction', 'isclose', 'load', 'loads', 'isscalar',
37+
'binary_repr', 'base_repr', 'ones', 'identity', 'allclose',
38+
'compare_chararrays', 'putmask', 'seterr', 'geterr', 'setbufsize',
39+
'getbufsize', 'seterrcall', 'geterrcall', 'errstate', 'flatnonzero',
40+
'Inf', 'inf', 'infty', 'Infinity', 'nan', 'NaN', 'False_', 'True_',
41+
'bitwise_not', 'CLIP', 'RAISE', 'WRAP', 'MAXDIMS', 'BUFSIZE',
42+
'ALLOW_THREADS', 'ComplexWarning', 'may_share_memory', 'full',
43+
'full_like', 'matmul',
44+
]
4845

4946
if sys.version_info[0] < 3:
5047
__all__.extend(['getbuffer', 'newbuffer'])
@@ -1281,7 +1278,7 @@ def tensordot(a, b, axes=2):
12811278
bs = b.shape
12821279
ndb = len(b.shape)
12831280
equal = True
1284-
if (na != nb):
1281+
if na != nb:
12851282
equal = False
12861283
else:
12871284
for k in range(na):

numpy/core/numerictypes.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@
8282
"""
8383
from __future__ import division, absolute_import, print_function
8484

85+
import types as _types
86+
import sys
87+
import numbers
88+
89+
from numpy.compat import bytes, long
90+
from numpy.core.multiarray import (
91+
typeinfo, ndarray, array, empty, dtype, datetime_data,
92+
datetime_as_string, busday_offset, busday_count, is_busday,
93+
busdaycalendar
94+
)
95+
96+
8597
# we add more at the bottom
8698
__all__ = ['sctypeDict', 'sctypeNA', 'typeDict', 'typeNA', 'sctypes',
8799
'ScalarType', 'obj2sctype', 'cast', 'nbytes', 'sctype2char',
@@ -90,15 +102,6 @@
90102
'busday_offset', 'busday_count', 'is_busday', 'busdaycalendar',
91103
]
92104

93-
from numpy.core.multiarray import (
94-
typeinfo, ndarray, array, empty, dtype, datetime_data,
95-
datetime_as_string, busday_offset, busday_count, is_busday,
96-
busdaycalendar
97-
)
98-
import types as _types
99-
import sys
100-
from numpy.compat import bytes, long
101-
import numbers
102105

103106
# we don't export these for import *, but we do want them accessible
104107
# as numerictypes.bool, etc.
@@ -328,15 +331,10 @@ def _add_aliases():
328331
sctypeNA[char] = na_name
329332
_add_aliases()
330333

331-
# Integers handled so that
332-
# The int32, int64 types should agree exactly with
333-
# PyArray_INT32, PyArray_INT64 in C
334-
# We need to enforce the same checking as is done
335-
# in arrayobject.h where the order of getting a
336-
# bit-width match is:
337-
# long, longlong, int, short, char
338-
# for int8, int16, int32, int64, int128
339-
334+
# Integers are handled so that the int32 and int64 types should agree
335+
# exactly with NPY_INT32, NPY_INT64. We need to enforce the same checking
336+
# as is done in arrayobject.h where the order of getting a bit-width match
337+
# is long, longlong, int, short, char.
340338
def _add_integer_aliases():
341339
_ctypes = ['LONG', 'LONGLONG', 'INT', 'SHORT', 'BYTE']
342340
for ctype in _ctypes:
@@ -960,6 +958,7 @@ def _register_types():
960958
numbers.Integral.register(integer)
961959
numbers.Complex.register(inexact)
962960
numbers.Real.register(floating)
961+
963962
_register_types()
964963

965964
def find_common_type(array_types, scalar_types):

numpy/core/setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
import imp
44
import os
55
import sys
6-
import shutil
76
import pickle
87
import copy
98
import warnings
10-
import re
119
from os.path import join
1210
from numpy.distutils import log
1311
from distutils.dep_util import newer
@@ -381,7 +379,7 @@ def visibility_define(config):
381379

382380
def configuration(parent_package='',top_path=None):
383381
from numpy.distutils.misc_util import Configuration, dot_join
384-
from numpy.distutils.system_info import get_info, default_lib_dirs
382+
from numpy.distutils.system_info import get_info
385383

386384
config = Configuration('core', parent_package, top_path)
387385
local_dir = config.local_path

numpy/core/setup_common.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
# Code common to build tools
44
import sys
5-
from os.path import join
65
import warnings
76
import copy
87
import binascii
98

10-
from distutils.ccompiler import CompileError
119

1210
#-------------------
1311
# Versioning support
@@ -54,11 +52,13 @@ def is_released(config):
5452
return True
5553

5654
def get_api_versions(apiversion, codegen_dir):
57-
"""Return current C API checksum and the recorded checksum for the given
58-
version of the C API version."""
59-
api_files = [join(codegen_dir, 'numpy_api_order.txt'),
60-
join(codegen_dir, 'ufunc_api_order.txt')]
55+
"""
56+
Return current C API checksum and the recorded checksum.
57+
58+
Return current C API checksum and the recorded checksum for the given
59+
version of the C API version.
6160
61+
"""
6262
# Compute the hash of the current API as defined in the .txt files in
6363
# code_generators
6464
sys.path.insert(0, codegen_dir)

numpy/core/shape_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'stack']
55

66
from . import numeric as _nx
7-
from .numeric import array, asanyarray, newaxis
7+
from .numeric import asanyarray, newaxis
88

99
def atleast_1d(*arys):
1010
"""

0 commit comments

Comments
 (0)
0