Repository: scikit-hep/hist
Pull request #487 (2023-03-21 00:00:29)

chore: update pre-commit hooks
<!--pre-commit.ci start-->
updates:
- [github.com/charliermarsh/ruff-pre-commit: v0.0.255 → v0.0.257](https://github.com/charliermarsh/ruff-pre-commit/compare/v0.0.255...v0.0.257)
- [github.com/nbQA-dev/nbQA: 1.6.3 → 1.6.4](https://github.com/nbQA-dev/nbQA/compare/1.6.3...1.6.4)
<!--pre-commit.ci end-->


Patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 6d2d77e..0139ef2 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -23,7 +23,7 @@ repos:
   - id: trailing-whitespace
 
 - repo: https://github.com/charliermarsh/ruff-pre-commit
-  rev: v0.0.255
+  rev: v0.0.258
   hooks:
   - id: ruff
     args: ["--fix", "--show-fixes"]
@@ -35,7 +35,7 @@ repos:
 
 # Notebook formatting
 - repo: https://github.com/nbQA-dev/nbQA
-  rev: 1.6.3
+  rev: 1.6.4
   hooks:
   - id: nbqa-ruff
     additional_dependencies: [ruff==0.0.253]
diff --git a/src/hist/__init__.py b/src/hist/__init__.py
index ca1ea5d..bbe9a66 100644
--- a/src/hist/__init__.py
+++ b/src/hist/__init__.py
@@ -54,6 +54,6 @@ def __dir__() -> tuple[str, ...]:
 def __getattr__(name: str) -> ModuleType:
     if name == "axes":
         msg = f"Misspelling error, '{name}' should be 'axis'"
-        warnings.warn(msg)
+        warnings.warn(msg, stacklevel=2)
         return axis
     raise AttributeError(f"module {__name__} has no attribute {name}")
diff --git a/src/hist/axestuple.py b/src/hist/axestuple.py
index 0ad8b7c..bcb1194 100644
--- a/src/hist/axestuple.py
+++ b/src/hist/axestuple.py
@@ -58,7 +58,7 @@ class NamedAxesTuple(AxesTuple):
                 disallowed_warning = (
                     f"{ax.name} is a protected keyword and cannot be used as axis name"
                 )
-                warnings.warn(disallowed_warning)
+                warnings.warn(disallowed_warning, stacklevel=2)
 
         valid_names = [ax.name for ax in self if ax.name]
         if len(valid_names) != len(set(valid_names)):
diff --git a/src/hist/basehist.py b/src/hist/basehist.py
index 1b8cba5..bfaaa8f 100644
--- a/src/hist/basehist.py
+++ b/src/hist/basehist.py
@@ -93,7 +93,7 @@ class BaseHist(bh.Histogram, metaclass=MetaConstructor, family=hist):
             storage = getattr(bh.storage, storage_str)()
         elif isinstance(storage, type):
             msg = f"Please use '{storage.__name__}()' instead of '{storage.__name__}'"
-            warnings.warn(msg)
+            warnings.warn(msg, stacklevel=2)
             storage = storage()
 
         super().__init__(*args, storage=storage, metadata=metadata)  # type: ignore[call-overload]
@@ -104,7 +104,7 @@ class BaseHist(bh.Histogram, metaclass=MetaConstructor, family=hist):
                 disallowed_warning = (
                     f"{ax.name} is a protected keyword and cannot be used as axis name"
                 )
-                warnings.warn(disallowed_warning)
+                warnings.warn(disallowed_warning, stacklevel=2)
 
         valid_names = [ax.name for ax in self.axes if ax.name]
         if len(valid_names) != len(set(valid_names)):


Test patch:
diff --git a/tests/test_stacks.py b/tests/test_stacks.py
index 777ea7e..e3ed7be 100644
--- a/tests/test_stacks.py
+++ b/tests/test_stacks.py
@@ -8,6 +8,8 @@ from pytest import approx
 
 from hist import Hist, NamedHist, Stack, axis
 
+np.random.seed(42)
+
 # different histograms here!
 reg_ax = axis.Regular(10, 0, 1)
 boo_ax = axis.Boolean()