Skip to content

Commit 7c34fb0

Browse files
authored
fix: drop metadata from repr (#454)
1 parent e53e757 commit 7c34fb0

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

src/boost_histogram/_internal/axis.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,6 @@ def _repr_kwargs(self):
147147
if not self.options.overflow:
148148
ret += ", overflow=False"
149149

150-
if self.metadata is not None and isinstance(self.metadata, str):
151-
if len(self.metadata) < 12:
152-
ret += ", metadata={!r}".format(self.metadata)
153-
else:
154-
ret += ", metadata={!r}...".format(self.metadata[:9])
155-
156150
return ret
157151

158152
@property
@@ -252,7 +246,7 @@ def __init__(self, bins, start, stop, **kwargs):
252246
stop : float
253247
The ending value for the axis
254248
metadata : Any
255-
Any Python object to attach to the axis.
249+
Fills .metadata on the axis.
256250
underflow : bool = True
257251
Enable the underflow bin
258252
overflow : bool = True
@@ -494,9 +488,6 @@ def _repr_kwargs(self):
494488
elif self.options.circular:
495489
ret += ", circular=True"
496490

497-
if self.metadata is not None:
498-
ret += ", metadata={0!r}".format(self.metadata)
499-
500491
return ret
501492

502493

@@ -642,7 +633,4 @@ def _repr_kwargs(self):
642633
just in case it spans multiple lines.
643634
"""
644635

645-
if self.metadata is not None:
646-
return "metadata={0!r}".format(self.metadata)
647-
else:
648-
return ""
636+
return ""

tests/test_axis.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,16 @@ def test_repr(self):
188188
assert repr(ax) == "Regular(4, 1.1, 2.2)"
189189

190190
ax = bh.axis.Regular(4, 1.1, 2.2, metadata="ra")
191-
assert repr(ax) == "Regular(4, 1.1, 2.2, metadata='ra')"
191+
assert repr(ax) == "Regular(4, 1.1, 2.2)"
192192

193193
ax = bh.axis.Regular(4, 1.1, 2.2, underflow=False)
194194
assert repr(ax) == "Regular(4, 1.1, 2.2, underflow=False)"
195195

196196
ax = bh.axis.Regular(4, 1.1, 2.2, metadata="ra", overflow=False)
197-
assert repr(ax) == "Regular(4, 1.1, 2.2, overflow=False, metadata='ra')"
197+
assert repr(ax) == "Regular(4, 1.1, 2.2, overflow=False)"
198198

199199
ax = bh.axis.Regular(4, 1.1, 2.2, metadata="ra", circular=True)
200-
assert repr(ax) == "Regular(4, 1.1, 2.2, circular=True, metadata='ra')"
200+
assert repr(ax) == "Regular(4, 1.1, 2.2, circular=True)"
201201

202202
ax = bh.axis.Regular(4, 1.1, 2.2, transform=bh.axis.transform.log)
203203
assert repr(ax) == "Regular(4, 1.1, 2.2, transform=log)"
@@ -365,7 +365,7 @@ def test_repr(self):
365365
assert repr(ax) == "Regular(4, 1.1, 2.2, circular=True)"
366366

367367
ax = bh.axis.Regular(4, 1.1, 2.2, metadata="hi", circular=True)
368-
assert repr(ax) == "Regular(4, 1.1, 2.2, circular=True, metadata='hi')"
368+
assert repr(ax) == "Regular(4, 1.1, 2.2, circular=True)"
369369

370370
def test_getitem(self):
371371
a = bh.axis.Regular(2, 1, 1 + np.pi * 2, circular=True)
@@ -475,7 +475,7 @@ def test_repr(self):
475475
assert repr(a) == "Variable([-0.1, 0.2])"
476476

477477
a = bh.axis.Variable([-0.1, 0.2], metadata="hi")
478-
assert repr(a) == "Variable([-0.1, 0.2], metadata='hi')"
478+
assert repr(a) == "Variable([-0.1, 0.2])"
479479

480480
def test_getitem(self):
481481
ref = [-0.1, 0.2, 0.3]
@@ -589,7 +589,7 @@ def test_repr(self):
589589
assert repr(a) == "Integer(-1, 1)"
590590

591591
a = bh.axis.Integer(-1, 1, metadata="hi")
592-
assert repr(a) == "Integer(-1, 1, metadata='hi')"
592+
assert repr(a) == "Integer(-1, 1)"
593593

594594
a = bh.axis.Integer(-1, 1, underflow=False)
595595
assert repr(a) == "Integer(-1, 1, underflow=False)"
@@ -708,14 +708,14 @@ def test_repr(self):
708708
assert repr(ax) == "IntCategory([1, 2, 3])"
709709

710710
ax = bh.axis.IntCategory([1, 2, 3], metadata="foo")
711-
assert repr(ax) == "IntCategory([1, 2, 3], metadata='foo')"
711+
assert repr(ax) == "IntCategory([1, 2, 3])"
712712

713713
ax = bh.axis.StrCategory("ABC", metadata="foo")
714714
# If unicode is the default (Python 3, generally)
715715
if type("") == type(u""): # noqa: E721
716-
assert repr(ax) == "StrCategory(['A', 'B', 'C'], metadata='foo')"
716+
assert repr(ax) == "StrCategory(['A', 'B', 'C'])"
717717
else:
718-
assert repr(ax) == "StrCategory([u'A', u'B', u'C'], metadata='foo')"
718+
assert repr(ax) == "StrCategory([u'A', u'B', u'C'])"
719719

720720
@pytest.mark.parametrize("ref", ([1, 2, 3], "ABC"))
721721
def test_getitem(self, ref, growth):
@@ -811,7 +811,7 @@ def test_repr(self):
811811
assert repr(a) == "Boolean()"
812812

813813
a = bh.axis.Boolean(metadata="hi")
814-
assert repr(a) == "Boolean(metadata='hi')"
814+
assert repr(a) == "Boolean()"
815815

816816
def test_label(self):
817817
a = bh.axis.Boolean(metadata="foo")

0 commit comments

Comments
 (0)