diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 9f1e9fd..2f5cfab 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -37,7 +37,7 @@ run --all-files` to check even without installing the hook. # Testing -Use PyTest to run the unit checks: +Use pytest to run the unit checks: ```bash pytest diff --git a/.github/dependabot.yml b/.github/dependabot.yml index c1eac3c..2700384 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,6 +6,6 @@ updates: schedule: interval: "daily" ignore: - # Offical actions have moving tags like v1 + # Official actions have moving tags like v1 # that are used, so they don't need updates here - dependency-name: "actions/*" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8dbf97b..dab4712 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -41,5 +41,31 @@ repos: hooks: - id: mypy files: ^(src|tests) - args: [] + args: [--show-error-codes] additional_dependencies: [numpy==1.22.*, pytest, importlib_metadata] + +- repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.9.0 + hooks: + - id: python-check-blanket-noqa + - id: python-check-blanket-type-ignore + - id: python-no-log-warn + - id: python-no-eval + - id: python-use-type-annotations + - id: rst-backticks + - id: rst-directive-colons + - id: rst-inline-touching-normal + +- repo: https://github.com/codespell-project/codespell + rev: v2.1.0 + hooks: + - id: codespell + args: ["-L", "hist,thist,ans,nd,gaus"] + +- repo: local + hooks: + - id: disallow-caps + name: Disallow improper capitalization + language: pygrep + entry: PyBind|Numpy|Cmake|CCache|Github|PyTest + exclude: .pre-commit-config.yaml diff --git a/docs/index.rst b/docs/index.rst index a0bb04f..0f925f9 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,7 +1,7 @@ .. uhi documentation master file, created by sphinx-quickstart on Tue Jan 19 16:19:27 2021. You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. + contain the root ``toctree`` directive. UHI: Unified Histogram Interface ================================= diff --git a/docs/indexing.rst b/docs/indexing.rst index 81caf7f..631048c 100644 --- a/docs/indexing.rst +++ b/docs/indexing.rst @@ -82,7 +82,7 @@ are slices, and follow the rules listed above. This looks like: h[{7: slice(0, 2, bh.rebin(4))}] # slice and rebin axis 7 -If you don't like manually building slices, you can use the `Slicer()` utility +If you don't like manually building slices, you can use the ``Slicer()`` utility to recover the original slicing syntax inside the dict: .. code:: python3 @@ -118,8 +118,8 @@ Rejected proposals or proposals for future consideration, maybe ``hist``-only: .. code:: python3 - h2 = h[1.0j:2.5j + 1] # Adding a j suffix to a number could be used in place of `loc(x)` - h2 = h[1.0] # Floats in place of `loc(x)`: too easy to make a mistake + h2 = h[1.0j:2.5j + 1] # Adding a j suffix to a number could be used in place of ``loc(x)`` + h2 = h[1.0] # Floats in place of ``loc(x)``: too easy to make a mistake Examples -------- @@ -255,7 +255,7 @@ Basic implementation example (WIP): "When used in the start or stop of a Histogram's slice, x is taken to be the position in data coordinates." def __init__(self, value, offset): self.value = value - self.offset = offest + self.offset = offset # supporting __add__ and __sub__ also recommended diff --git a/docs/plotting.rst b/docs/plotting.rst index 9ca994a..82dc351 100644 --- a/docs/plotting.rst +++ b/docs/plotting.rst @@ -24,7 +24,7 @@ Plotters should only depend on the methods and attributes listed below. In short Axes have: -* ``ax[i]``: A tuple of (lower, upper) bin, or the discrete bin value (integer or sting) +* ``ax[i]``: A tuple of (lower, upper) bin, or the discrete bin value (integer or string) * ``len(ax)``: The number of bins * Iteration is supported * ``ax.traits.circular``: True if circular diff --git a/src/uhi/numpy_plottable.py b/src/uhi/numpy_plottable.py index 5dd52ae..b0ba758 100644 --- a/src/uhi/numpy_plottable.py +++ b/src/uhi/numpy_plottable.py @@ -69,14 +69,14 @@ def __getitem__(self, index: int) -> Tuple[float, float]: Get the pair of edges (not discrete) or bin label (discrete). """ - return tuple(self.edges[index]) # type: ignore + return tuple(self.edges[index]) # type: ignore[return-value] def __len__(self) -> int: """ Return the number of bins (not counting flow bins, which are ignored for this Protocol currently). """ - return self.edges.shape[0] # type: ignore + return self.edges.shape[0] # type: ignore[no-any-return] def __eq__(self, other: Any) -> bool: """ @@ -133,14 +133,14 @@ def __init__( self._variances = variances if len(bins) == 1 and isinstance(bins[0], tuple): - (bins,) = bins # type: ignore + (bins,) = bins # type: ignore[assignment] if len(bins) == 0: bins = tuple([None] * len(hist.shape)) self.kind = kind self.axes: Sequence[PlottableAxis] = [ - _bin_helper(shape, b) for shape, b in zip(hist.shape, bins) # type: ignore + _bin_helper(shape, b) for shape, b in zip(hist.shape, bins) # type: ignore[arg-type] ] def __repr__(self) -> str: @@ -184,7 +184,7 @@ def __init__(self, tAxis: Any) -> None: self.tAx = tAxis def __len__(self) -> int: - return self.tAx.GetNbins() # type: ignore + return self.tAx.GetNbins() # type: ignore[no-any-return] def __getitem__(self, index: int) -> Any: pass @@ -226,7 +226,7 @@ def traits(self) -> PlottableTraits: return Traits(circular=False, discrete=True) def __getitem__(self, index: int) -> str: - return self.tAx.GetBinLabel(index + 1) # type: ignore + return self.tAx.GetBinLabel(index + 1) # type: ignore[no-any-return] def __iter__(self) -> Iterator[str]: for i in range(len(self)): @@ -248,7 +248,7 @@ def __init__(self, thist: Any) -> None: @property def name(self) -> str: - return self.thist.GetName() # type: ignore + return self.thist.GetName() # type: ignore[no-any-return] class ROOTPlottableHistogram(ROOTPlottableHistBase): @@ -264,13 +264,13 @@ def kind(self) -> str: return Kind.COUNT def values(self) -> "np.typing.NDArray[Any]": - return _roottarray_asnumpy(self.thist, shape=self._shape)[ # type: ignore + return _roottarray_asnumpy(self.thist, shape=self._shape)[ # type: ignore[no-any-return] tuple([slice(1, -1)] * len(self._shape)) ] def variances(self) -> "np.typing.NDArray[Any]": if self.hasWeights: - return _roottarray_asnumpy(self.thist.GetSumw2(), shape=self._shape)[ # type: ignore + return _roottarray_asnumpy(self.thist.GetSumw2(), shape=self._shape)[ # type: ignore[no-any-return] tuple([slice(1, -1)] * len(self._shape)) ] else: @@ -281,7 +281,7 @@ def counts(self) -> "np.typing.NDArray[Any]": return self.values() sumw = self.values() - return np.divide( # type: ignore + return np.divide( # type: ignore[no-any-return] sumw ** 2, self.variances(), out=np.zeros_like(sumw, dtype=np.float64), @@ -298,12 +298,12 @@ def kind(self) -> str: return Kind.MEAN def values(self) -> "np.typing.NDArray[Any]": - return np.array( # type: ignore + return np.array( # type: ignore[no-any-return] [self.thist.GetBinContent(i) for i in range(self.thist.GetNcells())] ).reshape(self._shape, order="F")[tuple([slice(1, -1)] * len(self._shape))] def variances(self) -> "np.typing.NDArray[Any]": - return ( # type: ignore + return ( # type: ignore[no-any-return] np.array([self.thist.GetBinError(i) for i in range(self.thist.GetNcells())]) ** 2 ).reshape(self._shape, order="F")[tuple([slice(1, -1)] * len(self._shape))] @@ -313,12 +313,12 @@ def counts(self) -> "np.typing.NDArray[Any]": tuple([slice(1, -1)] * len(self._shape)) ] if not (self.thist.GetSumw2() and self.thist.GetSumw2N()): - return sumw # type: ignore + return sumw # type: ignore[no-any-return] sumw2 = _roottarray_asnumpy(self.thist.GetSumw2(), shape=self._shape)[ tuple([slice(1, -1)] * len(self._shape)) ] - return np.divide( # type: ignore + return np.divide( # type: ignore[no-any-return] sumw ** 2, sumw2, out=np.zeros_like(sumw, dtype=np.float64), diff --git a/tests/test_uhi.py b/tests/test_uhi.py index 1f1fbc7..143813f 100644 --- a/tests/test_uhi.py +++ b/tests/test_uhi.py @@ -9,4 +9,4 @@ def test_version() -> None: - assert __version__ == metadata.version("uhi") # type: ignore + assert __version__ == metadata.version("uhi") # type: ignore[no-untyped-call]