Skip to content

Commit

Permalink
Fixed issues indicated by flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
vyrjana committed Aug 29, 2024
1 parent bbfbf8d commit d8ec7c1
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 70 deletions.
6 changes: 3 additions & 3 deletions src/pyimpspec/analysis/drt/bht.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ def _single_hilbert_transform_estimate(
kw = {}
else:
kw = {"category": OptimizeWarning}

with warnings.catch_warnings(**kw):
warnings.simplefilter("ignore")
res: OptimizeResult = minimize(
Expand Down Expand Up @@ -1243,10 +1243,10 @@ def calculate_drt_bht(

A_im: NDArray[float64] = _compute_A_im(w, tau)
prog.increment()

A_H_re: NDArray[float64] = _compute_A_H_re(w, tau)
prog.increment()

A_H_im: NDArray[float64] = _compute_A_H_im(w, tau)
prog.increment()

Expand Down
2 changes: 1 addition & 1 deletion src/pyimpspec/analysis/drt/tr_nnls.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def calculate_drt_tr_nnls(
if not isinstance(mode, str):
raise TypeError(f"Expected a string instead of {mode=}")
elif mode not in _MODES:
raise ValueError(f"Valid mode values: '" + "', '".join(_MODES))
raise ValueError("Valid mode values: '" + "', '".join(_MODES))

if not _is_floating(lambda_value):
raise TypeError(f"Expected a float instead of {lambda_value=}")
Expand Down
2 changes: 1 addition & 1 deletion src/pyimpspec/analysis/drt/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def _l_curve_corner_search(

def update_lambda(lambdas: List[float], index: int):
if index not in (1, 2):
raise ValueError(f"Expected the index to be 1 or 2")
raise ValueError("Expected the index to be 1 or 2")

xs: NDArray[float64] = log(lambdas)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,18 @@ def calculate_curvatures(Z: ComplexImpedances) -> NDArray[float64]:
NDArray[float64]
"""
kappa: NDArray[float64] = zeros((Z.size - 2, 3), dtype=float64)

a: NDArray[float64] = zeros((Z.size - 2, 2), dtype=float64)
a[:,0] = (Z[1:-1] - Z[:-2]).real
a[:,1] = (Z[1:-1] - Z[:-2]).imag
a[:, 0] = (Z[1:-1] - Z[:-2]).real
a[:, 1] = (Z[1:-1] - Z[:-2]).imag

b: NDArray[float64] = zeros((Z.size - 2, 2), dtype=float64)
b[:,0] = (Z[2:] - Z[1:-1]).real
b[:,1] = (Z[2:] - Z[1:-1]).imag
b[:, 0] = (Z[2:] - Z[1:-1]).real
b[:, 1] = (Z[2:] - Z[1:-1]).imag

c: NDArray[float64] = zeros((Z.size - 2, 2), dtype=float64)
c[:,0] = (Z[2:] - Z[:-2]).real
c[:,1] = (Z[2:] - Z[:-2]).imag
c[:, 0] = (Z[2:] - Z[:-2]).real
c[:, 1] = (Z[2:] - Z[:-2]).imag

a_dot_b: NDArray[float64] = zeros(Z.size - 2, dtype=float64)
a_norm: NDArray[float64] = zeros(Z.size - 2, dtype=float64)
Expand All @@ -209,12 +209,12 @@ def calculate_curvatures(Z: ComplexImpedances) -> NDArray[float64]:

i: int
for i in range(0, a.shape[0]):
a_dot_b[i] = dot(a[i,:], b[i,:])
a_norm[i] = norm(a[i,:])
b_norm[i] = norm(b[i,:])
a_dot_b[i] = dot(a[i, :], b[i, :])
a_norm[i] = norm(a[i, :])
b_norm[i] = norm(b[i, :])
a_norm_dot_b_norm[i] = dot(a_norm[i], b_norm[i])
cos_alpha[i] = a_dot_b[i] / a_norm_dot_b_norm[i]
c_norm[i] = norm(c[i,:])
c_norm[i] = norm(c[i, :])

indices: NDArray[int64] = argwhere(cos_alpha < -1.0).flatten()
if indices.size > 0:
Expand All @@ -235,12 +235,12 @@ def calculate_curvatures(Z: ComplexImpedances) -> NDArray[float64]:
abs_kappa: NDArray[float64] = 2 * sin(alpha) / c_norm

matrix: NDArray[float64] = ones((Z.size, 3), dtype=float64)
matrix[:,0] = Z.real
matrix[:,1] = -Z.imag
matrix[:, 0] = Z.real
matrix[:, 1] = -Z.imag
determinant: NDArray[float64] = zeros(Z.size - 2, dtype=float64)

for i in range(0, a.shape[0]):
determinant[i] = det(matrix[i:i+3,:])
determinant[i] = det(matrix[i:i+3, :])

kappa: NDArray[float64] = abs_kappa * sign(determinant)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ def _fit_intersecting_lines(
p0=(s1, o1, s2, o2),
maxfev=1000,
)[0]
except RuntimeError as e1:
except RuntimeError:
continue
except TypeError as e2:
except TypeError:
break

return tuple(p)
Expand Down Expand Up @@ -191,7 +191,7 @@ def _approximate_transition_and_end_point(

# Some test implementations may have a very significant drop in
# X²ps at high num_RC when the number of points per decade is low.
while (log_pseudo_chisqrs[i-1] - log_pseudo_chisqrs[i]) > 1.0:
while (log_pseudo_chisqrs[i-1] - log_pseudo_chisqrs[i]) > 1.0:
i -= 1

max_num_RC: int = int(max(num_RCs[:i]))
Expand Down
14 changes: 7 additions & 7 deletions src/pyimpspec/analysis/kramers_kronig/exploratory.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def _calculate_statistic(
if target_num_RC > 0:
i: int = argmin(abs(x - target_num_RC))

return mean(y[i : i + 2])
return mean(y[i:i + 2])

# Unable to estimate the target num_RC at
# log(fits.log_F_ext) = 0 for some reason.
Expand Down Expand Up @@ -617,8 +617,8 @@ def _fit_cubic_and_interpolate(
i = max((0, k - 2 * delta))

if (k - i) == (2 * delta) and (k - i) > 3:
x = x[i : k + 1]
y = y[i : k + 1]
x = x[i:k + 1]
y = y[i:k + 1]

p: Tuple[float, float, float, float] = _fit_cubic_function(x, y)

Expand Down Expand Up @@ -772,8 +772,8 @@ def backup_approach(x: NDArray[float64], y: NDArray[float64]):
m = min(argwhere(smooth_y <= max(rel_std)).flatten())
n = max(argwhere(smooth_y >= min(rel_std)).flatten())
ax2.plot(
smooth_x[m : n + 1],
smooth_y[m : n + 1],
smooth_x[m:n + 1],
smooth_y[m:n + 1],
color="green",
linestyle=":",
)
Expand All @@ -799,8 +799,8 @@ def backup_approach(x: NDArray[float64], y: NDArray[float64]):
m = min(argwhere(smooth_y <= max(y)).flatten())
n = max(argwhere(smooth_y >= min(y)).flatten())
ax1.plot(
smooth_x[m : n + 1],
smooth_y[m : n + 1],
smooth_x[m:n + 1],
smooth_y[m:n + 1],
color="black",
linestyle=":",
)
Expand Down
14 changes: 7 additions & 7 deletions src/pyimpspec/analysis/kramers_kronig/least_squares.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _add_resistance_to_A_matrix(
i: int = 0

if test == "complex":
A[0 : m // 2, i] = 1
A[0:m // 2, i] = 1
elif test == "real":
A[0:m, i] = 1

Expand Down Expand Up @@ -117,8 +117,8 @@ def _add_kth_variables_to_A_matrix(

m: int = A.shape[0]
if test == "complex":
A[0 : m // 2, i] = c.real
A[m // 2 :, i] = c.imag
A[0:m // 2, i] = c.real
A[m // 2:, i] = c.imag
elif test == "real":
A[0:m, i] = c.real
else:
Expand All @@ -135,7 +135,7 @@ def _add_capacitance_to_A_matrix(
m: int = A.shape[0]

if test == "complex":
A[m // 2 :, i] = w if admittance else (-1 / w)
A[m // 2:, i] = w if admittance else (-1 / w)
elif test == "imaginary":
A[:, i] = w if admittance else (-1 / w)

Expand All @@ -150,7 +150,7 @@ def _add_inductance_to_A_matrix(
m: int = A.shape[0]

if test == "complex":
A[m // 2 :, i] = (1 / w) if admittance else w
A[m // 2:, i] = (1 / w) if admittance else w
elif test == "imaginary":
A[:, i] = (1 / w) if admittance else w

Expand Down Expand Up @@ -227,8 +227,8 @@ def _add_values_to_b_vector(
m: int = b.shape[0]

if test == "complex":
b[0 : m // 2] = (Z_exp ** (-1 if admittance else 1)).real
b[m // 2 :] = (Z_exp ** (-1 if admittance else 1)).imag
b[0:m // 2] = (Z_exp ** (-1 if admittance else 1)).real
b[m // 2:] = (Z_exp ** (-1 if admittance else 1)).imag
elif test == "real":
b[0:m] = (Z_exp ** (-1 if admittance else 1)).real
else:
Expand Down
4 changes: 2 additions & 2 deletions src/pyimpspec/analysis/zhit/smoothing/modified_sinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def _extend_data(
At each end, m extrapolated points are appended.
"""
extended_data: NDArray[float64] = zeros(len(data) + 2 * m, dtype=float64)
extended_data[m : m + len(data)] = data
extended_data[m:m + len(data)] = data

lin_reg: LinearRegression = LinearRegression()

Expand Down Expand Up @@ -376,7 +376,7 @@ def _smooth(
kernel,
)

return extended_smoothed[radius : radius + len(data)]
return extended_smoothed[radius:radius + len(data)]


def _smooth_like_savgol(
Expand Down
2 changes: 1 addition & 1 deletion src/pyimpspec/circuit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ def _get_elements_recursive(self) -> List[Element]:
)

if len(elements) != len(set(elements)):
raise ValueError(f"Detected duplicate elements")
raise ValueError("Detected duplicate elements")

return elements

Expand Down
2 changes: 1 addition & 1 deletion src/pyimpspec/circuit/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def process(self, string: str, version: int = -1) -> Circuit:
if (
string == ""
or string == "[]"
or (string.startswith("!") and string[string.find("!", 1) + 1 :] == "[]")
or (string.startswith("!") and string[string.find("!", 1) + 1:] == "[]")
):
self.push_stack(Series([]))
else:
Expand Down
2 changes: 1 addition & 1 deletion src/pyimpspec/circuit/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _initialized():

key: str
element: Type[Element]
for key, element in _DEFAULT_ELEMENTS.items():
for key, element in _DEFAULT_ELEMENTS.items():
_DEFAULT_ELEMENT_PARAMETERS[key] = element.get_default_values().copy()


Expand Down
2 changes: 1 addition & 1 deletion src/pyimpspec/circuit/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def push(self, Class: Type[Token]):
if Class is Number or Class is FixedNumber:
value = float(self._value)
else:
value = self._original[self._start : self._end]
value = self._original[self._start:self._end]

self._tokens.append(Class(self._start, self._end, value))
self._start = self._index
Expand Down
2 changes: 1 addition & 1 deletion src/pyimpspec/cli/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def exploratory_tests(
raise err
else:
raise ValueError(
f"Expected to successfully test at least one representation"
"Expected to successfully test at least one representation"
)

test: KramersKronigResult
Expand Down
2 changes: 1 addition & 1 deletion src/pyimpspec/cli/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def _parse_identity(identity: str) -> Tuple[str, dict]:

i: int = identity.rfind(":")
if ":" in identity and i > max(map(lambda s: identity.rfind(s), ("}", "]", ")"))):
for arg in identity[i + 1 :].split(","):
for arg in identity[i + 1:].split(","):
key, value = arg.split("=")
if key in kwarg_types:
kwargs[key] = kwarg_types[key](value)
Expand Down
2 changes: 1 addition & 1 deletion src/pyimpspec/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def parse_data(
if not isinstance(data_sets, list):
raise TypeError(f"Expected a list instead of {data_sets=}")
elif len(data_sets) == 0:
raise ValueError(f"Expected a list with at least one element")
raise ValueError("Expected a list with at least one element")
elif not all(map(lambda _: isinstance(_, DataSet), data_sets)):
raise TypeError(f"Expected a list of DataSet instead of {data_sets=}")
elif not all(map(lambda _: _.get_label().strip() != "", data_sets)):
Expand Down
4 changes: 2 additions & 2 deletions src/pyimpspec/data/data_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(
)
elif not (len(frequencies) == len(impedances) > 0):
raise ValueError(
f"Expected the frequency and impedance arrays to be of equal length and have at least 1 element each"
"Expected the frequency and impedance arrays to be of equal length and have at least 1 element each"
)
elif len(unique(frequencies)) != len(frequencies):
raise ValueError(
Expand Down Expand Up @@ -395,7 +395,7 @@ def average(cls, data_sets: List["DataSet"], label: str = "Average") -> "DataSet
frequencies,
)
):
raise ValueError(f"Expected all frequency arrays to have the same values")
raise ValueError("Expected all frequency arrays to have the same values")

Z: ComplexImpedances = mean(array(impedances), axis=0)

Expand Down
2 changes: 1 addition & 1 deletion src/pyimpspec/data/formats/pssession.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def parse_pssession(path: Union[str, Path]) -> List[DataSet]:
json: dict = loads(contents[i:j])
if "Measurements" not in json:
raise UnsupportedFileFormat(
f"Expected to find a 'Measurements' key in the file"
"Expected to find a 'Measurements' key in the file"
)

dataframes: Dict[str, DataFrame] = {}
Expand Down
4 changes: 2 additions & 2 deletions src/pyimpspec/plot/mpl/kramers_kronig.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ def _plot_suggestion_method_1(
j = max(argwhere(y >= -0.05).flatten())
axes[0].axhline(p[0] + p[3], color=COLOR_RED, linestyle=":")
axes[0].plot(
x[i : j + 1],
y[i : j + 1],
x[i:j + 1],
y[i:j + 1],
color=COLOR_RED,
linestyle=":",
)
Expand Down
Loading

0 comments on commit d8ec7c1

Please sign in to comment.