diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cbe9162..0b7e216 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ ci: repos: - repo: https://github.com/adamchainz/blacken-docs - rev: "1.16.0" + rev: "1.18.0" hooks: - id: blacken-docs additional_dependencies: [black==24.*] @@ -33,14 +33,14 @@ repos: - id: rst-inline-touching-normal - repo: https://github.com/pre-commit/mirrors-prettier - rev: "v3.1.0" + rev: "v4.0.0-alpha.8" hooks: - id: prettier types_or: [yaml, markdown, html, css, scss, javascript, json] args: [--prose-wrap=always] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.4.1" + rev: "v0.5.1" hooks: - id: ruff args: ["--fix", "--show-fixes"] @@ -56,7 +56,7 @@ repos: # - pytest - repo: https://github.com/codespell-project/codespell - rev: "v2.2.6" + rev: "v2.3.0" hooks: - id: codespell @@ -74,13 +74,13 @@ repos: exclude: .pre-commit-config.yaml - repo: https://github.com/abravalheri/validate-pyproject - rev: "v0.16" + rev: "v0.18" hooks: - id: validate-pyproject additional_dependencies: ["validate-pyproject-schema-store[all]"] - repo: https://github.com/python-jsonschema/check-jsonschema - rev: "0.28.2" + rev: "0.28.6" hooks: - id: check-dependabot - id: check-github-workflows diff --git a/src/cuda_histogram/hist_tools.py b/src/cuda_histogram/hist_tools.py index 6add0c3..88c1236 100644 --- a/src/cuda_histogram/hist_tools.py +++ b/src/cuda_histogram/hist_tools.py @@ -83,7 +83,7 @@ def overflow_behavior(overflow): elif overflow == "justnan": return slice(-1, None) else: - raise ValueError("Unrecognized overflow behavior: %s" % overflow) + raise ValueError(f"Unrecognized overflow behavior: {overflow}") @functools.total_ordering @@ -144,7 +144,7 @@ def __eq__(self, other): return False if other.nan() and self.nan(): return True - if self._lo == other._lo and self._hi == other._hi: + if self._lo == other._lo and self._hi == other._hi: # noqa: SIM103 return True return False @@ -195,7 +195,7 @@ class StringBin: def __init__(self, name, label=None): if not isinstance(name, basestring): raise TypeError( - "StringBin only supports string categories, received a %r" % name + f"StringBin only supports string categories, received a {name!r}" ) elif "*" in name: raise ValueError( @@ -269,16 +269,14 @@ def label(self, label): def __eq__(self, other): if isinstance(other, Axis): - if self._name != other._name: + if self._name != other._name: # noqa: SIM103 return False # label doesn't matter return True elif isinstance(other, basestring): # Convenient for testing axis in list by name - if self._name != other: - return False - return True - raise TypeError("Cannot compare an Axis with a %r" % other) + return not self._name != other + raise TypeError(f"Cannot compare an Axis with a {other!r}") class SparseAxis(Axis): @@ -356,7 +354,7 @@ def __eq__(self, other): def __getitem__(self, index): if not isinstance(index, StringBin): - raise TypeError("Expected a StringBin object, got: %r" % index) + raise TypeError(f"Expected a StringBin object, got: {index!r}") identifier = index.name if identifier not in self._bins: raise KeyError("No identifier %r in this Category axis") @@ -375,7 +373,7 @@ def _ireduce(self, the_slice): elif isinstance(the_slice, list): if not all(k in self._sorted for k in the_slice): warnings.warn( - "Not all requested indices present in %r" % self, RuntimeWarning + f"Not all requested indices present in {self!r}", RuntimeWarning ) out = [k for k in self._sorted if k in the_slice] elif isinstance(the_slice, slice): @@ -419,7 +417,7 @@ def sorting(self, newsorting): # this will be checked in any Hist.identifiers() call accessing this axis pass else: - raise AttributeError("Invalid axis sorting type: %s" % newsorting) + raise AttributeError(f"Invalid axis sorting type: {newsorting}") self._sorting = newsorting def identifiers(self): @@ -501,7 +499,7 @@ def __init__(self, name, label, n_or_arr, lo=None, hi=None): self._bin_names = np.full(self._interval_bins[:-1].size, None) else: raise TypeError( - "Cannot understand n_or_arr (nbins or binning array) type %r" % n_or_arr + f"Cannot understand n_or_arr (nbins or binning array) type {n_or_arr!r}" ) @property @@ -603,7 +601,7 @@ def __eq__(self, other): return False if self._uniform and self._bins != other._bins: return False - if not self._uniform and not all(self._bins == other._bins): + if not self._uniform and not all(self._bins == other._bins): # noqa: SIM103 return False return True return super().__eq__(other) @@ -1028,7 +1026,7 @@ def compatible(self, other): d.name for d in other.sparse_axes() }: return False - if not all(d1 == d2 for d1, d2 in zip(self.dense_axes(), other.dense_axes())): + if not all(d1 == d2 for d1, d2 in zip(self.dense_axes(), other.dense_axes())): # noqa: SIM103 return False return True @@ -1036,8 +1034,7 @@ def add(self, other): """Add another histogram into this one, in-place""" if not self.compatible(other): raise ValueError( - "Cannot add this histogram with histogram %r of dissimilar dimensions" - % other + f"Cannot add this histogram with histogram {other!r} of dissimilar dimensions" ) raxes = other.sparse_axes() diff --git a/src/cuda_histogram/plot.py b/src/cuda_histogram/plot.py index a0af7aa..6184817 100644 --- a/src/cuda_histogram/plot.py +++ b/src/cuda_histogram/plot.py @@ -216,7 +216,7 @@ def plot1d( raise ValueError("Cannot use density and binwnorm at the same time!") if binwnorm is not None and not isinstance(binwnorm, numbers.Number): raise ValueError( - "Bin width normalization not a number, but a %r" % binwnorm.__class__ + f"Bin width normalization not a number, but a {binwnorm.__class__!r}" ) if line_opts is None and fill_opts is None and error_opts is None: if stack: @@ -447,7 +447,7 @@ def plotratio( normal_interval(sumw_num, sumw_denom, sumw2_num, sumw2_denom) ) else: - raise ValueError("Unrecognized uncertainty option: %r" % unc) + raise ValueError(f"Unrecognized uncertainty option: {unc!r}") if error_opts is not None: opts = {"label": label, "linestyle": "none"} @@ -546,7 +546,7 @@ def plot2d( raise ValueError("Cannot use density and binwnorm at the same time!") if binwnorm is not None and not isinstance(binwnorm, numbers.Number): raise ValueError( - "Bin width normalization not a number, but a %r" % binwnorm.__class__ + f"Bin width normalization not a number, but a {binwnorm.__class__!r}" ) if patch_opts is None and text_opts is None: patch_opts = {} @@ -666,7 +666,7 @@ def plotgrid( "More than one dimension left: {}".format(",".join(ax for ax in haxes)) ) elif len(haxes) == 0: - raise ValueError("Not enough dimensions available in %r" % h) + raise ValueError(f"Not enough dimensions available in {h!r}") figsize = plt.rcParams["figure.figsize"] figsize = figsize[0] * max(ncol, 1), figsize[1] * max(nrow, 1)