Repository: scikit-hep/hist

Issue:
[BUG] Repr issues
The integer repr is missing name/label, and label gets repeated even if it's just picking it up from name for the other axes, like Regular.

Discussion:
sourcery-ai[bot]: # Sourcery Code Quality Report


Merging this PR leaves code quality **unchanged**.

| Quality metrics | Before | After | Change |
| --- | :---: | :---: | :---: |
| [Complexity](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report#complexity) | 0.94 ⭐ | 0.94 ⭐ | 0.00  |
| [Method Length](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report#method-length) | 31.33 ⭐ | 31.33 ⭐ | 0.00  |
| [Working memory](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report#working-memory) | 7.49 🙂 | 7.49 🙂 | 0.00  |
| **[Quality](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report#quality-score)** | **83.98%** ⭐| **83.98%** ⭐| **0.00%**  |



| Other metrics | Before | After | Change |
| --- | :---: | :---: | :---: |
| Lines | 197 | 197 | 0 |



| Changed files | Quality Before | Quality After | Quality Change |
| --- | :---: | :---: | :---: |
| src/hist/axis/__init__.py | 83.98% ⭐ | 83.98% ⭐ | 0.00% |



Here are some functions in these files that still need a tune-up:

| File | Function | Complexity | Length | Working Memory | Quality | Recommendation |
| --- | --- | :---: | :---: | :---: | :---: | --- |
| src/hist/axis/__init__.py | Regular.\_\_init\_\_ | 2 ⭐ | 71 🙂 | 17 ⛔ | 61.22% 🙂 | Extract out complex expressions |
| src/hist/axis/__init__.py | Integer.\_\_init\_\_ | 2 ⭐ | 65 🙂 | 15 😞 | 64.25% 🙂 | Extract out complex expressions |
| src/hist/axis/__init__.py | Variable.\_\_init\_\_ | 2 ⭐ | 63 🙂 | 14 😞 | 65.82% 🙂 | Extract out complex expressions |


## Legend and Explanation

The emojis denote the absolute quality of the code:

 - ⭐ excellent
 - 🙂 good
 - 😞 poor
 - ⛔ very poor


The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.

***

Please see our documentation [here](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report) for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us [improve](https://research.typeform.com/to/j06Spdfr?type=quality_report&github_login=amangoel185&base_repo=https%3A%2F%2Fgithub.com%2Fscikit-hep%2Fhist.git&base_remote_ref=refs%2Fpull%2F241%2Fhead&base_ref=main&base_sha=dbcda6594b6e076b8dbf10e006143bc815a2c462&head_repo=https%3A%2F%2Fgithub.com%2Fscikit-hep%2Fhist.git&head_ref=sourcery%2Fpull-241&base_pr_number=241&base_pr_state=open) this quality report!
henryiii: Could you add a test for the repr to make this doesn't happen again?
amangoel185: Sure
amangoel185: Sure, I'll do that.
sourcery-ai[bot]: # Sourcery Code Quality Report


❌ &nbsp;Merging this PR will **decrease** code quality in the affected files by **2.66%**.

| Quality metrics | Before | After | Change |
| --- | :---: | :---: | :---: |
| [Complexity](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report#complexity) | 0.62 ⭐ | 0.44 ⭐ | -0.18 👍 |
| [Method Length](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report#method-length) | 30.38 ⭐ | 36.48 ⭐ | 6.10 👎 |
| [Working memory](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report#working-memory) | 7.04 🙂 | 7.58 🙂 | 0.54 👎 |
| **[Quality](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report#quality-score)** | **85.63%** ⭐| **82.97%** ⭐| **-2.66%** 👎 |



| Other metrics | Before | After | Change |
| --- | :---: | :---: | :---: |
| Lines | 232 | 268 | 36 |



| Changed files | Quality Before | Quality After | Quality Change |
| --- | :---: | :---: | :---: |
| src/hist/axis/__init__.py | 83.98% ⭐ | 83.98% ⭐ | 0.00% |
| tests/test_reprs.py | 88.86% ⭐ | 82.10% ⭐ | -6.76% 👎|



Here are some functions in these files that still need a tune-up:

| File | Function | Complexity | Length | Working Memory | Quality | Recommendation |
| --- | --- | :---: | :---: | :---: | :---: | --- |
| src/hist/axis/__init__.py | Regular.\_\_init\_\_ | 2 ⭐ | 71 🙂 | 17 ⛔ | 61.22% 🙂 | Extract out complex expressions |
| src/hist/axis/__init__.py | Integer.\_\_init\_\_ | 2 ⭐ | 65 🙂 | 15 😞 | 64.25% 🙂 | Extract out complex expressions |
| src/hist/axis/__init__.py | Variable.\_\_init\_\_ | 2 ⭐ | 63 🙂 | 14 😞 | 65.82% 🙂 | Extract out complex expressions |
| tests/test_reprs.py | test\_ND\_empty\_repr | 0 ⭐ | 80 🙂 | 12 😞 | 68.22% 🙂 | Extract out complex expressions |


## Legend and Explanation

The emojis denote the absolute quality of the code:

 - ⭐ excellent
 - 🙂 good
 - 😞 poor
 - ⛔ very poor


The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.

***

Please see our documentation [here](https://github.com/sourcery-ai/sourcery/wiki/Quality-Report) for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us [improve](https://research.typeform.com/to/j06Spdfr?type=quality_report&github_login=amangoel185&base_repo=https%3A%2F%2Fgithub.com%2Fscikit-hep%2Fhist.git&base_remote_ref=refs%2Fpull%2F241%2Fhead&base_ref=main&base_sha=9775449add4e3974a1cd15b29a844d955e0fecf8&head_repo=https%3A%2F%2Fgithub.com%2Fscikit-hep%2Fhist.git&head_ref=sourcery%2Fpull-241&base_pr_number=241&base_pr_state=open) this quality report!
amangoel185: I've added the tests, @henryiii. You can merge it if it looks good to you.

Patch:
diff --git a/src/hist/axis/__init__.py b/src/hist/axis/__init__.py
index 87af714..a528a17 100644
--- a/src/hist/axis/__init__.py
+++ b/src/hist/axis/__init__.py
@@ -141,7 +141,7 @@ class Boolean(AxesMixin, bha.Boolean, family=hist):
         self.label: str = label
 
 
-class Variable(bha.Variable, AxesMixin, family=hist):
+class Variable(AxesMixin, bha.Variable, family=hist):
     __slots__ = ()
 
     def __init__(
@@ -150,12 +150,12 @@ class Variable(bha.Variable, AxesMixin, family=hist):
         *,
         name: str = "",
         label: str = "",
+        metadata: Any = None,
         flow: bool = True,
         underflow: Optional[bool] = None,
         overflow: Optional[bool] = None,
         growth: bool = False,
         circular: bool = False,
-        metadata: Any = None,
         __dict__: Optional[Dict[str, Any]] = None,
     ) -> None:
         super().__init__(
@@ -171,7 +171,7 @@ class Variable(bha.Variable, AxesMixin, family=hist):
         self.label: str = label
 
 
-class Integer(bha.Integer, AxesMixin, family=hist):
+class Integer(AxesMixin, bha.Integer, family=hist):
     __slots__ = ()
 
     def __init__(
@@ -181,12 +181,12 @@ class Integer(bha.Integer, AxesMixin, family=hist):
         *,
         name: str = "",
         label: str = "",
+        metadata: Any = None,
         flow: bool = True,
         underflow: Optional[bool] = None,
         overflow: Optional[bool] = None,
         growth: bool = False,
         circular: bool = False,
-        metadata: Any = None,
         __dict__: Optional[Dict[str, Any]] = None,
     ) -> None:
         super().__init__(
@@ -203,7 +203,7 @@ class Integer(bha.Integer, AxesMixin, family=hist):
         self.label: str = label
 
 
-class IntCategory(bha.IntCategory, AxesMixin, family=hist):
+class IntCategory(AxesMixin, bha.IntCategory, family=hist):
     __slots__ = ()
 
     def __init__(
@@ -212,8 +212,8 @@ class IntCategory(bha.IntCategory, AxesMixin, family=hist):
         *,
         name: str = "",
         label: str = "",
-        growth: bool = False,
         metadata: Any = None,
+        growth: bool = False,
         __dict__: Optional[Dict[str, Any]] = None,
     ) -> None:
         super().__init__(
@@ -226,7 +226,7 @@ class IntCategory(bha.IntCategory, AxesMixin, family=hist):
         self.label: str = label
 
 
-class StrCategory(bha.StrCategory, AxesMixin, family=hist):
+class StrCategory(AxesMixin, bha.StrCategory, family=hist):
     __slots__ = ()
 
     def __init__(
@@ -235,8 +235,8 @@ class StrCategory(bha.StrCategory, AxesMixin, family=hist):
         *,
         name: str = "",
         label: str = "",
-        growth: bool = False,
         metadata: Any = None,
+        growth: bool = False,
         __dict__: Optional[Dict[str, Any]] = None,
     ) -> None:
         super().__init__(


Test patch:
diff --git a/tests/test_reprs.py b/tests/test_reprs.py
index 58317d3..19e98a4 100644
--- a/tests/test_reprs.py
+++ b/tests/test_reprs.py
@@ -1,45 +1,85 @@
 def test_1D_empty_repr(named_hist):
 
-    h = named_hist.new.Reg(10, -1, 1, name="x").Double()
+    h = named_hist.new.Reg(10, -1, 1, name="x", label="y").Double()
     html = h._repr_html_()
     assert html
+    assert "name='x'" in repr(h)
+    assert "label='y'" in repr(h)
+
+
+def test_1D_var_empty_repr(named_hist):
+
+    h = named_hist.new.Var(range(10), name="x", label="y").Double()
+    html = h._repr_html_()
+    assert html
+    assert "name='x'" in repr(h)
+    assert "label='y'" in repr(h)
+
+
+def test_1D_int_empty_repr(named_hist):
+
+    h = named_hist.new.Int(-9, 9, name="x", label="y").Double()
+    html = h._repr_html_()
+    assert html
+    assert "name='x'" in repr(h)
+    assert "label='y'" in repr(h)
 
 
 def test_1D_intcat_empty_repr(named_hist):
 
-    h = named_hist.new.IntCat([1, 3, 5], name="x").Double()
+    h = named_hist.new.IntCat([1, 3, 5], name="x", label="y").Double()
     html = h._repr_html_()
     assert html
+    assert "name='x'" in repr(h)
+    assert "label='y'" in repr(h)
 
 
 def test_1D_strcat_empty_repr(named_hist):
 
-    h = named_hist.new.StrCat(["1", "3", "5"], name="x").Double()
+    h = named_hist.new.StrCat(["1", "3", "5"], name="x", label="y").Double()
     html = h._repr_html_()
     assert html
+    assert "name='x'" in repr(h)
+    assert "label='y'" in repr(h)
 
 
 def test_2D_empty_repr(named_hist):
 
-    h = named_hist.new.Reg(10, -1, 1, name="x").Int(0, 15, name="y").Double()
+    h = (
+        named_hist.new.Reg(10, -1, 1, name="x", label="y")
+        .Int(0, 15, name="p", label="q")
+        .Double()
+    )
     html = h._repr_html_()
     assert html
+    assert "name='x'" in repr(h)
+    assert "name='p'" in repr(h)
+    assert "label='y'" in repr(h)
+    assert "label='q'" in repr(h)
 
 
 def test_1D_circ_empty_repr(named_hist):
 
-    h = named_hist.new.Reg(10, -1, 1, circular=True, name="r").Double()
+    h = named_hist.new.Reg(10, -1, 1, circular=True, name="R", label="r").Double()
     html = h._repr_html_()
     assert html
+    assert "name='R'" in repr(h)
+    assert "label='r'" in repr(h)
 
 
 def test_ND_empty_repr(named_hist):
 
     h = (
-        named_hist.new.Reg(10, -1, 1, name="x")
-        .Reg(12, -3, 3, name="y")
-        .Reg(15, -2, 4, name="z")
+        named_hist.new.Reg(10, -1, 1, name="x", label="y")
+        .Reg(12, -3, 3, name="p", label="q")
+        .Reg(15, -2, 4, name="a", label="b")
         .Double()
     )
     html = h._repr_html_()
     assert html
+    assert "name='x'" in repr(h)
+    assert "name='p'" in repr(h)
+    assert "name='a'" in repr(h)
+    assert "label='y'" in repr(h)
+    assert "label='q'" in repr(h)
+    assert "label='b'" in repr(h)