Skip to content

Commit 7867a0a

Browse files
committed
Fix some code issues from codacy
1 parent ec9c023 commit 7867a0a

File tree

7 files changed

+380
-33
lines changed

7 files changed

+380
-33
lines changed

Stoner/Image/imagefuncs.py

+1
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ def convert(image, dtype, force_copy=False, uniform=False, normalise=True):
360360
result = np.where(~image, *dtype_range[dtype])
361361
return result
362362

363+
imax = imin = imax_in = imin_in = None
363364
if dtypeobj.kind in "ui":
364365
imin = np.iinfo(dtype).min
365366
imax = np.iinfo(dtype).max

Stoner/analysis/filtering.py

+27-24
Original file line numberDiff line numberDiff line change
@@ -292,30 +292,33 @@ def extrapolate(self, new_x, xcol=None, ycol=None, yerr=None, overlap=20, kind="
292292
work = self.clone
293293
for ix, x in enumerate(new_x):
294294
r = self.closest(x, xcol=_.xcol)
295-
if isinstance(overlap, int):
296-
if (r.i - overlap / 2) < 0:
297-
ll = 0
298-
hl = min(len(self), overlap)
299-
elif (r.i + overlap / 2) > len(self):
300-
hl = len(self)
301-
ll = max(hl - overlap, 0)
302-
else:
303-
ll = r.i - overlap / 2
304-
hl = r.i + overlap / 2
305-
bounds = {"_i__between": (ll, hl)}
306-
mid_x = (self[ll, _.xcol] + self[hl - 1, _.xcol]) / 2.0
307-
elif isinstance(overlap, float):
308-
if (r[_.xcol] - overlap / 2) < self.min(_.xcol)[0]:
309-
ll = self.min(_.xcol)[0]
310-
hl = ll + overlap
311-
elif (r[_.xcol] + overlap / 2) > self.max(_.xcol)[0]:
312-
hl = self.max(_.xcol)[0]
313-
ll = hl - overlap
314-
else:
315-
ll = r[_.xcol] - overlap / 2
316-
hl = r[_.xcol] + overlap / 2
317-
bounds = {f"{self.column_headers[_.xcol]}__between": (ll, hl)}
318-
mid_x = (ll + hl) / 2.0
295+
match overlap:
296+
case int():
297+
if (r.i - overlap / 2) < 0:
298+
ll = 0
299+
hl = min(len(self), overlap)
300+
elif (r.i + overlap / 2) > len(self):
301+
hl = len(self)
302+
ll = max(hl - overlap, 0)
303+
else:
304+
ll = r.i - overlap / 2
305+
hl = r.i + overlap / 2
306+
bounds = {"_i__between": (ll, hl)}
307+
mid_x = (self[ll, _.xcol] + self[hl - 1, _.xcol]) / 2.0
308+
case float():
309+
if (r[_.xcol] - overlap / 2) < self.min(_.xcol)[0]:
310+
ll = self.min(_.xcol)[0]
311+
hl = ll + overlap
312+
elif (r[_.xcol] + overlap / 2) > self.max(_.xcol)[0]:
313+
hl = self.max(_.xcol)[0]
314+
ll = hl - overlap
315+
else:
316+
ll = r[_.xcol] - overlap / 2
317+
hl = r[_.xcol] + overlap / 2
318+
bounds = {f"{self.column_headers[_.xcol]}__between": (ll, hl)}
319+
mid_x = (ll + hl) / 2.0
320+
case _:
321+
raise TypeError(f"Overlap should be an integer or floating point number not a {type(overlap)}")
319322
pointdata = work.select(**bounds)
320323
pointdata.data[:, _.xcol] = pointdata.column(_.xcol) - mid_x
321324
ret = pointdata.curve_fit(kindf, _.xcol, _.ycol, sigma=_.yerr, absolute_sigma=True)

Stoner/core/setas.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
__all__ = ["setas"]
55
import re
66
import copy
7-
from collections.abc import MutableMapping, Mapping, Iterable
7+
from collections.abc import MutableMapping, Iterable
88

99
import numpy as np
1010

11-
from ..compat import string_types, int_types, index_types, _pattern_type
11+
from ..compat import string_types, index_types, _pattern_type
1212
from ..tools import AttributeStore, isiterable, typedList, isLikeList
1313
from .utils import decode_string
1414

@@ -339,7 +339,8 @@ def __contains__(self, item):
339339
def __delitem__(self, name):
340340
"""Unset either by column index or column assignment.
341341
342-
Equivalent to unsetting the same object."""
342+
Equivalent to unsetting the same object.
343+
"""
343344
self.unset(name)
344345

345346
def __eq__(self, other):
@@ -445,7 +446,7 @@ def __setitem__(self, name, value):
445446
case "x" | "y" | "z" | "u" | "v" | "w" | "d" | "e" | "f" | "." | "-":
446447
for c in self.find_col(value, force_list=True):
447448
self._setas[c] = name
448-
case int() | str() | _pattern_type() if value in [letter for letter in "xyzuvwdef.-"]:
449+
case int() | str() | _pattern_type() if value in list("xyzuvwdef.-"):
449450
for c in self.find_col(name, force_list=True):
450451
self.setas[c] = value
451452
case _:
@@ -646,21 +647,24 @@ def get(self, key, default=None): # pylint: disable=arguments-differ
646647
def keys(self):
647648
"""Access mapping keys.
648649
649-
Mapping keys are the same as iterating over the unique headers"""
650+
Mapping keys are the same as iterating over the unique headers
651+
"""
650652
for c in self._unique_headers:
651653
yield c
652654

653655
def values(self):
654656
"""Access mapping values.
655657
656-
Mapping values are the same as iterating over setas."""
658+
Mapping values are the same as iterating over setas.
659+
"""
657660
for v in self.setas:
658661
yield v
659662

660663
def items(self):
661664
"""Access mapping items.
662665
663-
Mapping items iterates over keys and values."""
666+
Mapping items iterates over keys and values.
667+
"""
664668
for k, v in zip(self._unique_headers, self.setas):
665669
yield k, v
666670

@@ -746,7 +750,8 @@ def to_dict(self):
746750
"""Return the setas attribute as a dictionary.
747751
748752
If multiple columns are assigned to the same type, then the column names are
749-
returned as a list. If column headers are duplicated"""
753+
returned as a list. If column headers are duplicated.
754+
"""
750755
ret = dict()
751756
for k, ch in zip(self._setas, self._unique_headers):
752757
if k != ".":
@@ -766,7 +771,8 @@ def to_list(self):
766771
def to_string(self, encode=False):
767772
"""Return the setas attribute encoded as a string.
768773
769-
Optionally replaces runs of 3 or more identical characters with a precediung digit."""
774+
Optionally replaces runs of 3 or more identical characters with a precediung digit.
775+
"""
770776
expanded = "".join(self)
771777
if encode:
772778
pat = re.compile(r"((.)\2{2,9})")

0 commit comments

Comments
 (0)