Skip to content

Commit

Permalink
fix pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Saransh-cpp committed Jul 13, 2024
1 parent 7a869a0 commit 0c781d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
29 changes: 13 additions & 16 deletions src/cuda_histogram/hist_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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")
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1028,16 +1026,15 @@ 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

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()
Expand Down
8 changes: 4 additions & 4 deletions src/cuda_histogram/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"}
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0c781d6

Please sign in to comment.