Repository: scikit-hep/hist

Issue:
[BUG] Integer axes counts as category for plot
The categorical plotting from #174 tried to trigger on integer axes and breaks.

Discussion:
LovelyBuggies: This pr is trying to solve #201.

Patch:
diff --git a/src/hist/basehist.py b/src/hist/basehist.py
index a862c51..2158e49 100644
--- a/src/hist/basehist.py
+++ b/src/hist/basehist.py
@@ -343,7 +343,12 @@ class BaseHist(bh.Histogram, metaclass=MetaConstructor, family=hist):
         """
         Plot method for BaseHist object.
         """
-        _has_categorical = np.sum([ax.traits.discrete for ax in self.axes]) == 1
+        _has_categorical = 0
+        if (
+            np.sum(self.axes.traits.ordered) == 1
+            and np.sum(self.axes.traits.discrete) == 1
+        ):
+            _has_categorical = 1
         _project = _has_categorical or overlay is not None
         if self.ndim == 1 or (self.ndim == 2 and _project):
             return self.plot1d(*args, overlay=overlay, **kwargs)


Test patch:
diff --git a/tests/test_mock_plot.py b/tests/test_mock_plot.py
new file mode 100644
index 0000000..7407712
--- /dev/null
+++ b/tests/test_mock_plot.py
@@ -0,0 +1,41 @@
+import numpy as np
+import pytest
+
+from hist import Hist
+
+
+@pytest.fixture(autouse=True)
+def mock_test(monkeypatch):
+    monkeypatch.setattr(Hist, "plot1d", plot1d_mock)
+    monkeypatch.setattr(Hist, "plot2d", plot2d_mock)
+
+
+def plot1d_mock(*args, **kwargs):
+    return "called plot1d"
+
+
+def plot2d_mock(*args, **kwargs):
+    return "called plot2d"
+
+
+def test_categorical_plot():
+    testCat = (
+        Hist.new.StrCat("", name="dataset", growth=True)
+        .Reg(10, 0, 10, name="good", label="y-axis")
+        .Int64()
+    )
+
+    testCat.fill(dataset="A", good=np.random.normal(5, 9, 27))
+
+    assert testCat.plot() == "called plot1d"
+
+
+def test_integer_plot():
+    testInt = (
+        Hist.new.Int(1, 10, name="nice", label="x-axis")
+        .Reg(10, 0, 10, name="good", label="y-axis")
+        .Int64()
+    )
+    testInt.fill(nice=np.random.normal(5, 1, 10), good=np.random.normal(5, 1, 10))
+
+    assert testInt.plot() == "called plot2d"