Skip to content

Commit

Permalink
chore(deps): update pre-commit hooks (#890)
Browse files Browse the repository at this point in the history
* chore(deps): update pre-commit hooks

updates:
- [github.com/pre-commit/pre-commit-hooks: v4.4.0 → v4.5.0](pre-commit/pre-commit-hooks@v4.4.0...v4.5.0)
- [github.com/asottile/setup-cfg-fmt: v2.4.0 → v2.5.0](asottile/setup-cfg-fmt@v2.4.0...v2.5.0)
- [github.com/astral-sh/ruff-pre-commit: v0.0.290 → v0.0.292](astral-sh/ruff-pre-commit@v0.0.290...v0.0.292)
- [github.com/codespell-project/codespell: v2.2.5 → v2.2.6](codespell-project/codespell@v2.2.5...v2.2.6)
- [github.com/shellcheck-py/shellcheck-py: v0.9.0.5 → v0.9.0.6](shellcheck-py/shellcheck-py@v0.9.0.5...v0.9.0.6)

* chore: update pre-commit and pylint

Signed-off-by: Henry Schreiner <[email protected]>

* chore: fixes for pylint and mypy

Signed-off-by: Henry Schreiner <[email protected]>

---------

Signed-off-by: Henry Schreiner <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Henry Schreiner <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and henryiii authored Oct 9, 2023
1 parent 7b36aa2 commit 18db55d
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 38 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ repos:
rev: "1.16.0"
hooks:
- id: blacken-docs
additional_dependencies: [black==23.7.0]
additional_dependencies: [black==23.9.1]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -41,7 +41,7 @@ repos:
types_or: [yaml, markdown, html, css, scss, javascript, json]

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.4.0
rev: v2.5.0
hooks:
- id: setup-cfg-fmt
args:
Expand All @@ -52,7 +52,7 @@ repos:
]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.0.290"
rev: "v0.0.292"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand All @@ -71,10 +71,10 @@ repos:
stages: [manual]

- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.2.6
hooks:
- id: codespell
args: ["-L", "hist,nd,circularly,ba"]
args: ["-L", "hist,nd,circularly,ba", "-w"]
exclude: ^(notebooks/xarray.ipynb|notebooks/BoostHistogramHandsOn.ipynb|.*\.svg)$

- repo: local
Expand All @@ -99,7 +99,7 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.5
rev: v0.9.0.6
hooks:
- id: shellcheck
exclude: ^docs/notebooks/conf.sh$
2 changes: 1 addition & 1 deletion notebooks/PerformanceComparison.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"source": [
"#### Traditional 1D NumPy Histogram\n",
"\n",
"This is reasonably optimized; it should provide good perforance."
"This is reasonably optimized; it should provide good performance."
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ def pylint(session: nox.Session) -> None:
Run pylint.
"""

session.install("pylint==2.14.*")
session.install("-e", ".")
session.install("pylint==2.17.*")
session.install(".")
session.run("pylint", "src", *session.posargs)


Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ skip = ["pp*-manylinux_i686", "cp312-win32"] # not supported by NumPy
environment-pass = ["SETUPTOOLS_SCM_PRETEND_VERSION"]
environment = { PIP_ONLY_BINARY = "numpy" }


[tool.pylint]
main.py-version = "3.7"
main.extension-pkg-allow-list = ["boost_histogram._core"]
py-version = "3.7"
extension-pkg-allow-list = ["boost_histogram._core"]
reports.output-format = "colorized"
similarities.ignore-imports = "yes"
messages_control.disable = [
Expand All @@ -108,7 +109,7 @@ messages_control.disable = [
"missing-class-docstring",
"missing-function-docstring",
"missing-module-docstring",
"no-member", # C extensions mess with this
"c-extension-no-member", # C extensions mess with this
"protected-access",
"too-few-public-methods",
"too-many-arguments",
Expand Down
2 changes: 1 addition & 1 deletion src/boost_histogram/_core/axis/transform.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def _sq_fn(arg0: float) -> float: ...

class _BaseTransform:
def forward(self, arg0: float) -> float: ...
def reverse(self, arg0: float) -> float: ...
def inverse(self, arg0: float) -> float: ...
def __repr__(self) -> str: ...
def __copy__(self: T) -> T: ...
def __deepcopy__(self: T, memo: Any) -> T: ...
Expand Down
32 changes: 17 additions & 15 deletions src/boost_histogram/_internal/axis_transform.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import copy
from typing import Any, TypeVar
from typing import Any, ClassVar, TypeVar

import boost_histogram

Expand All @@ -15,7 +15,7 @@
class AxisTransform:
__slots__ = ("_this",)
_family: object
_this: Any
_this: ca.transform._BaseTransform

def __init_subclass__(cls, *, family: object) -> None:
super().__init_subclass__()
Expand All @@ -39,41 +39,40 @@ def __repr__(self) -> str:
return f"{self.__class__.__name__}() # Missing _this, broken class"

def _produce(self, bins: int, start: float, stop: float) -> Any:
# Note: this is an ABC; _type must be defined on children
# These can be fixed later with a Protocol
return self.__class__._type(bins, start, stop) # type: ignore[attr-defined]
raise NotImplementedError()

def __init__(self) -> None:
"Create a new transform instance"
# Note: this comes from family
(cpp_class,) = self._types # type: ignore[attr-defined]
self._this = cpp_class()
raise NotImplementedError()

def forward(self, value: float) -> float:
"Compute the forward transform"
return self._this.forward(value) # type: ignore[no-any-return]
return self._this.forward(value)

def inverse(self, value: float) -> float:
"Compute the inverse transform"
return self._this.inverse(value) # type: ignore[no-any-return]
return self._this.inverse(value)


@set_module("boost_histogram.axis.transform")
@register({ca.transform.pow})
class Pow(AxisTransform, family=boost_histogram):
__slots__ = ()
_type = ca.regular_pow
_this: ca.transform.pow

# Note: this comes from family
_types: ClassVar[set[type[ca.transform.pow]]]

def __init__(self, power: float): # pylint: disable=super-init-not-called
"Create a new transform instance"
# Note: this comes from family
(cpp_class,) = self._types # type: ignore[attr-defined]
(cpp_class,) = self._types
self._this = cpp_class(power)

@property
def power(self) -> float:
"The power of the transform"
return self._this.power # type: ignore[no-any-return]
return self._this.power

# This one does need to be a normal method
def _produce(self, bins: int, start: float, stop: float) -> Any:
Expand All @@ -85,6 +84,10 @@ def _produce(self, bins: int, start: float, stop: float) -> Any:
class Function(AxisTransform, family=boost_histogram):
__slots__ = ()
_type = ca.regular_trans
_this: ca.transform.func_transform

# Note: this comes from family
_types: ClassVar[set[type[ca.transform.func_transform]]]

def __init__( # pylint: disable=super-init-not-called
self, forward: Any, inverse: Any, *, convert: Any = None, name: str = ""
Expand Down Expand Up @@ -135,8 +138,7 @@ def log(x):
"""

# Note: this comes from family
(cpp_class,) = self._types # type: ignore[attr-defined]
(cpp_class,) = self._types
self._this = cpp_class(forward, inverse, convert, name)

# This one does need to be a normal method
Expand Down
1 change: 1 addition & 0 deletions src/boost_histogram/_internal/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class Histogram:

axes: AxesTuple
_hist: CppHistogram
_variance_known: bool

def __init_subclass__(cls, *, family: object | None = None) -> None:
"""
Expand Down
4 changes: 2 additions & 2 deletions src/boost_histogram/_internal/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import boost_histogram

from .._core import accumulators
from .._core import storage as store
from .._core import accumulators # pylint: disable=no-name-in-module
from .._core import storage as store # pylint: disable=no-name-in-module
from .utils import set_module


Expand Down
17 changes: 11 additions & 6 deletions src/boost_histogram/_internal/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
import numpy as np

from ..accumulators import Mean, WeightedMean, WeightedSum
from .typing import ArrayLike, StrIndex, Ufunc
from .typing import ArrayLike, Literal, StrIndex, Ufunc

UFMethod = Literal["__call__", "reduce", "reduceat", "accumulate", "outer", "inner"]


class View(np.ndarray): # type: ignore[type-arg]
__slots__ = ()
_FIELDS: ClassVar[tuple[str, ...]]
_PARENT: type[WeightedSum] | type[WeightedMean] | type[Mean]

def __getitem__(self, ind: StrIndex) -> np.typing.NDArray[Any]: # type: ignore[override]
sliced = super().__getitem__(ind) # type: ignore[index]

# If the shape is empty, return the parent type
if not sliced.shape:
return self._PARENT._make(*sliced) # type: ignore[attr-defined, no-any-return]
return self._PARENT._make(*sliced) # type: ignore[no-any-return]

# If the dtype has changed, return a normal array (no longer a record)
if sliced.dtype != self.dtype:
Expand Down Expand Up @@ -47,7 +50,7 @@ def __setitem__(self, ind: StrIndex, value: ArrayLike) -> None:
msg = "Needs matching ndarray or n+1 dim array"
if array.ndim == current_ndim + 1:
if len(self._FIELDS) == array.shape[-1]:
self.__setitem__(ind, self._PARENT._array(*np.moveaxis(array, -1, 0))) # type: ignore[attr-defined]
self.__setitem__(ind, self._PARENT._array(*np.moveaxis(array, -1, 0)))
return
msg += f", final dimension should be {len(self._FIELDS)} for this storage, got {array.shape[-1]} instead"
raise ValueError(msg)
Expand Down Expand Up @@ -109,7 +112,7 @@ class WeightedSumView(View):

# Could be implemented on master View
def __array_ufunc__(
self, ufunc: Ufunc, method: str, *inputs: Any, **kwargs: Any
self, ufunc: Ufunc, method: UFMethod, *inputs: Any, **kwargs: Any
) -> np.typing.NDArray[Any]:
# Avoid infinite recursion
raw_inputs = [np.asarray(x) for x in inputs]
Expand Down Expand Up @@ -155,7 +158,8 @@ def __array_ufunc__(
return result.view(self.__class__) # type: ignore[no-any-return]

# If unsupported, just pass through (will return not implemented)
return super().__array_ufunc__(ufunc, method, *raw_inputs, **kwargs) # type: ignore[no-any-return, arg-type]
# pylint: disable-next=no-member
return super().__array_ufunc__(ufunc, method, *raw_inputs, **kwargs) # type: ignore[no-any-return]

# View with normal value or array
if ufunc in {np.add, np.subtract}:
Expand Down Expand Up @@ -234,7 +238,8 @@ def __array_ufunc__(
return result.view(self.__class__) # type: ignore[no-any-return]

# If unsupported, just pass through (will return NotImplemented or things like == will work but not return subclasses)
return super().__array_ufunc__(ufunc, method, *raw_inputs, **kwargs) # type: ignore[no-any-return, arg-type]
# pylint: disable-next=no-member
return super().__array_ufunc__(ufunc, method, *raw_inputs, **kwargs) # type: ignore[no-any-return]


@fields(
Expand Down
2 changes: 1 addition & 1 deletion src/boost_histogram/accumulators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from ._core.accumulators import ( # pylint: disable=import-error
from ._core.accumulators import ( # pylint: disable=import-error,no-name-in-module
Mean,
Sum,
WeightedMean,
Expand Down

0 comments on commit 18db55d

Please sign in to comment.