diff --git a/src/hist/axis/__init__.py b/src/hist/axis/__init__.py index 49a6d03c..1f0281e7 100644 --- a/src/hist/axis/__init__.py +++ b/src/hist/axis/__init__.py @@ -253,6 +253,11 @@ def __init__( __dict__: dict[str, Any] | None = None, ) -> None: has_flow = flow if overflow is None else overflow + + categories = list(categories) + if len(categories) != len(set(categories)): + raise ValueError("Categorical axis entries must be unique") + super().__init__( categories, metadata=metadata, diff --git a/tests/baseline/test_image_plot_pull.png b/tests/baseline/test_image_plot_pull.png index bb3ec178..a9bf1d99 100644 Binary files a/tests/baseline/test_image_plot_pull.png and b/tests/baseline/test_image_plot_pull.png differ diff --git a/tests/baseline/test_plot1d_auto_handling.png b/tests/baseline/test_plot1d_auto_handling.png index 1292b2e5..c5aa8f51 100644 Binary files a/tests/baseline/test_plot1d_auto_handling.png and b/tests/baseline/test_plot1d_auto_handling.png differ diff --git a/tests/test_axis.py b/tests/test_axis.py index 940c6fc7..32c1271f 100644 --- a/tests/test_axis.py +++ b/tests/test_axis.py @@ -64,3 +64,16 @@ def test_axis_disallowed_names(): hist.Hist(axis.Regular(10, 0, 10, name="sample")) with pytest.warns(UserWarning, match="threads is a protected keyword"): hist.Hist(axis.Regular(10, 0, 10, name="threads")) + + +def test_duplicate_strcategory(): + import hist + + try: + hist.axis.StrCategory(["a", "a"]) + raise RuntimeError( + "Axis creation should have failed due to duplicate categories" + ) + + except ValueError: + pass