Skip to content

Commit

Permalink
style: fix issues reported
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Jan 30, 2025
1 parent c450f12 commit 891a8a9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repos:
- id: mypy
files: ^src
args: []
additional_dependencies: ["numpy~=1.26.0", "matplotlib>=3.4", "boost-histogram~=1.4.0", "uhi~=0.3.1", "pandas-stubs>=2.0.1.230501"]
additional_dependencies: ["numpy~=2.2.0", "matplotlib>=3.4", "boost-histogram~=1.5.0", "uhi~=0.3.1", "pandas-stubs>=2.0.1.230501"]

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
Expand Down
8 changes: 4 additions & 4 deletions src/hist/basehist.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ def from_columns(
for ax in axes:
if isinstance(ax, str):
assert ax in data, f"{ax} must be present in data={list(data)}"
cats = set(data[ax]) # type: ignore[arg-type]
cats = set(data[ax])
if all(isinstance(a, str) for a in cats):
axes_list.append(hist.axis.StrCategory(sorted(cats), name=ax)) # type: ignore[arg-type]
axes_list.append(hist.axis.StrCategory(sorted(cats), name=ax))
elif all(isinstance(a, int) for a in cats):
axes_list.append(hist.axis.IntCategory(sorted(cats), name=ax)) # type: ignore[arg-type]
axes_list.append(hist.axis.IntCategory(sorted(cats), name=ax))
else:
raise TypeError(
f"{ax} must be all int or strings if axis not given"
Expand All @@ -214,7 +214,7 @@ def from_columns(

self = cls(*axes_list, storage=storage)
data_list = {x.name: data[x.name] for x in axes_list}
self.fill(**data_list, weight=weight_arr) # type: ignore[arg-type]
self.fill(**data_list, weight=weight_arr)
return self

def project(self, *args: int | str) -> Self | float | bh.accumulators.Accumulator:
Expand Down
4 changes: 2 additions & 2 deletions src/hist/interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def broadcast_and_flatten(
try:
arrays.append(np.asarray(arg))
except (TypeError, ValueError):
return NotImplemented
return NotImplemented # type: ignore[no-any-return]

return tuple(np.ravel(x) for x in np.broadcast_arrays(*arrays))

Expand All @@ -126,6 +126,6 @@ def broadcast_and_flatten(
try:
arrays.append(np.asarray(arg))
except (TypeError, ValueError):
return NotImplemented
return NotImplemented # type: ignore[no-any-return]

return tuple(np.ravel(x) for x in np.broadcast_arrays(*arrays))
2 changes: 1 addition & 1 deletion src/hist/intervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def clopper_pearson_interval(
interval = np.stack((interval_min, interval_max))
interval[0, num == 0.0] = 0.0
interval[1, num == denom] = 1.0
return interval # type: ignore[no-any-return]
return interval


def ratio_uncertainty(
Expand Down
2 changes: 1 addition & 1 deletion src/hist/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def plot_ratio_array(
valid_ratios + ratio_uncert[1][valid_ratios_idx],
]
)
max_delta = np.amax(np.abs(extrema - central_value))
max_delta: float = np.amax(np.abs(extrema - central_value))
ratio_extrema = np.abs(max_delta + central_value)

_alpha = 2.0
Expand Down
6 changes: 3 additions & 3 deletions src/hist/svgplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def svg_hist_1d(h: hist.BaseHist) -> svg:
(edges,) = h.axes.edges
norm_edges = (edges - edges[0]) / (edges[-1] - edges[0])
density = h.density()
max_dens = np.amax(density) or 1
max_dens: float = np.amax(density)
norm_vals: np.typing.NDArray[Any] = density / max_dens

arr: np.typing.NDArray[np.float64] = np.empty(
Expand Down Expand Up @@ -121,7 +121,7 @@ def svg_hist_1d_c(h: hist.BaseHist) -> svg:
(edges,) = h.axes.edges
norm_edges = (edges - edges[0]) / (edges[-1] - edges[0]) * np.pi * 2
density = h.density()
max_dens = np.amax(density) or 1
max_dens: float = np.amax(density)
norm_vals: np.typing.NDArray[Any] = density / max_dens

arr: np.typing.NDArray[np.float64] = np.empty((2, len(norm_vals) * 2), dtype=float)
Expand Down Expand Up @@ -155,7 +155,7 @@ def svg_hist_2d(h: hist.BaseHist) -> svg:
ey = -(e1 - e1[0]) / (e1[-1] - e1[0]) * height

density = h.density()
max_dens = np.amax(density) or 1
max_dens: float = np.amax(density)
norm_vals: np.typing.NDArray[Any] = density / max_dens

boxes = []
Expand Down

0 comments on commit 891a8a9

Please sign in to comment.