Skip to content

Commit

Permalink
MAINT: Fixes from static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
sethtroisi committed Aug 4, 2020
1 parent 034b1d3 commit aa2a3c6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 26 deletions.
10 changes: 5 additions & 5 deletions benchmarks/benchmarks/signal_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ def setup(self, n_samples, threads):
self.chunks = np.array_split(self.data, threads)

def time_sosfilt(self, n_samples, threads):
pool = ThreadPoolExecutor(max_workers=threads)
futures = []
for i in range(threads):
futures.append(pool.submit(sosfilt, self.filt, self.chunks[i]))
with ThreadPoolExecutor(max_workers=threads) as pool:
futures = []
for i in range(threads):
futures.append(pool.submit(sosfilt, self.filt, self.chunks[i]))

wait(futures)
wait(futures)


class Sosfilt(Benchmark):
Expand Down
15 changes: 8 additions & 7 deletions pavement.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ def release(options):
def compute_md5(idirs):
released = paver.path.path(idirs).listdir()
checksums = []
for f in sorted(released):
m = md5(open(f, 'rb').read())
for fn in sorted(released):
with open(fn, 'rb') as f:
m = md5(f.read())
checksums.append('%s %s' % (m.hexdigest(), os.path.basename(f)))

return checksums
Expand All @@ -217,8 +218,9 @@ def compute_sha256(idirs):
# to verify the binaries instead of signing all binaries
released = paver.path.path(idirs).listdir()
checksums = []
for f in sorted(released):
m = sha256(open(f, 'rb').read())
for fn in sorted(released):
with open(fn, 'rb') as f:
m = sha256(f.read())
checksums.append('%s %s' % (m.hexdigest(), os.path.basename(f)))

return checksums
Expand Down Expand Up @@ -267,9 +269,8 @@ def write_log_task(filename='Changelog'):
stdout=subprocess.PIPE)

out = st.communicate()[0].decode()
a = open(filename, 'w')
a.writelines(out)
a.close()
with open(filename, 'w') as a:
a.writelines(out)

@task
@cmdopts([('gpg_key=', 'g', 'GPG key to use for signing')])
Expand Down
4 changes: 2 additions & 2 deletions scipy/optimize/_dual_annealing.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ def local_search(self, x, e):
# Run local search from the given x location where energy value is e
x_tmp = np.copy(x)
mres = self.minimizer(self.func_wrapper.fun, x, **self.kwargs)
if 'njev' in mres.keys():
if 'njev' in mres:
self.func_wrapper.ngev += mres.njev
if 'nhev' in mres.keys():
if 'nhev' in mres:
self.func_wrapper.nhev += mres.nhev
# Check if is valid value
is_finite = np.all(np.isfinite(mres.x)) and np.isfinite(mres.fun)
Expand Down
2 changes: 1 addition & 1 deletion scipy/special/_generate_pyx.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def generate_fused_type(codes):
Valid inputs to CY_TYPES (i.e. f, d, g, ...).
"""
cytypes = map(lambda x: CY_TYPES[x], codes)
cytypes = [CY_TYPES[x] for x in codes]
name = codes + "_number_t"
declaration = ["ctypedef fused " + name + ":"]
for cytype in cytypes:
Expand Down
14 changes: 5 additions & 9 deletions scipy/special/tests/test_sf_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ def _check_action(fun, args, action):
def test_geterr():
err = sc.geterr()
for key, value in err.items():
assert_(key in _sf_error_code_map.keys())
assert_(key in _sf_error_code_map)
assert_(value in _sf_error_actions)


def test_seterr():
entry_err = sc.geterr()
try:
for category in _sf_error_code_map.keys():
for category, error_code in _sf_error_code_map.items():
for action in _sf_error_actions:
geterr_olderr = sc.geterr()
seterr_olderr = sc.seterr(**{category: action})
Expand All @@ -61,9 +61,7 @@ def test_seterr():
geterr_olderr.pop(category)
newerr.pop(category)
assert_(geterr_olderr == newerr)
_check_action(_sf_error_test_function,
(_sf_error_code_map[category],),
action)
_check_action(_sf_error_test_function, (error_code,), action)
finally:
sc.seterr(**entry_err)

Expand Down Expand Up @@ -93,13 +91,11 @@ def test_errstate_cpp_basic():


def test_errstate():
for category in _sf_error_code_map.keys():
for category, error_code in _sf_error_code_map.items():
for action in _sf_error_actions:
olderr = sc.geterr()
with sc.errstate(**{category: action}):
_check_action(_sf_error_test_function,
(_sf_error_code_map[category],),
action)
_check_action(_sf_error_test_function, (error_code,), action)
assert_equal(olderr, sc.geterr())


Expand Down
4 changes: 2 additions & 2 deletions tools/refguide_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ def check_items(all_dict, names, deprecated, others, module_name, dots=True):
output += "Objects in refguide: %i\n\n" % num_ref

only_all, only_ref, missing = compare(all_dict, others, names, module_name)
dep_in_ref = set(only_ref).intersection(deprecated)
only_ref = set(only_ref).difference(deprecated)
dep_in_ref = only_ref.intersection(deprecated)
only_ref = only_ref.difference(deprecated)

if len(dep_in_ref) > 0:
output += "Deprecated objects in refguide::\n\n"
Expand Down

0 comments on commit aa2a3c6

Please sign in to comment.