Repository: scikit-hep/hist

Issue:
[BUG] Hist does not forbid axes names that are reserved keywords for fill
None of these names are legal because they are reserved in the `fill` signature
```python
import hist

h = hist.Hist(
    hist.axis.Regular(10, 0, 10, name="weight"),
    hist.axis.Regular(10, 0, 10, name="sample"),
    hist.axis.Regular(10, 0, 10, name="threads"),
)
h.fill(weight=1, sample=2, threads=3)
```

Discussion:

Patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 86aaad1..fc9220b 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -24,7 +24,7 @@ repos:
   - id: isort
 
 - repo: https://github.com/asottile/pyupgrade
-  rev: v2.19.4
+  rev: v2.20.0
   hooks:
   - id: pyupgrade
     args: [--py36-plus]
diff --git a/src/hist/basehist.py b/src/hist/basehist.py
index 2158e49..9543663 100644
--- a/src/hist/basehist.py
+++ b/src/hist/basehist.py
@@ -94,6 +94,13 @@ class BaseHist(bh.Histogram, metaclass=MetaConstructor, family=hist):
                 warnings.warn(msg)
                 storage = storage()
             super().__init__(*args, storage=storage, metadata=metadata)  # type: ignore
+
+            disallowed_names = {"weight", "sample", "threads"}
+            for ax in self.axes:
+                if ax.name in disallowed_names:
+                    disallowed_warning = f"{ax.name} is a protected keyword and cannot be used as axis name"
+                    warnings.warn(disallowed_warning)
+
             valid_names = [ax.name for ax in self.axes if ax.name]
             if len(valid_names) != len(set(valid_names)):
                 raise KeyError(
@@ -203,7 +210,9 @@ class BaseHist(bh.Histogram, metaclass=MetaConstructor, family=hist):
         }
 
         if set(data_dict) != set(range(len(args), self.ndim)):
-            raise TypeError("All axes must be accounted for in fill")
+            raise TypeError(
+                "All axes must be accounted for in fill, you may have used a disallowed name in the axes"
+            )
 
         data = (data_dict[i] for i in range(len(args), self.ndim))
 


Test patch:
diff --git a/tests/test_axis.py b/tests/test_axis.py
index a9217b6..286f6dd 100644
--- a/tests/test_axis.py
+++ b/tests/test_axis.py
@@ -1,4 +1,6 @@
-from hist import axis
+import pytest
+
+from hist import axis, hist
 
 
 def test_axis_names():
@@ -51,3 +53,13 @@ def test_axis_flow():
     assert axis.Integer(0, 8, flow=False, overflow=True) == axis.Integer(
         0, 8, underflow=False
     )
+
+
+def test_axis_disallowed_names():
+
+    with pytest.warns(UserWarning):
+        hist.Hist(axis.Regular(10, 0, 10, name="weight"))
+    with pytest.warns(UserWarning):
+        hist.Hist(axis.Regular(10, 0, 10, name="sample"))
+    with pytest.warns(UserWarning):
+        hist.Hist(axis.Regular(10, 0, 10, name="threads"))