-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Describe the bug
Currently, AxesTuple inherits the constructor behavior of tuple in that it requires an iterable. While this makes sense and is consistent, it can create a hard-to-spot bug introduced by the fact that a single axis is also iterable and therefore if not an iterable of one or more axes but a single axis is given, it won't fail on instantiation. However, it will fail when trying to use any attribute.
I would propose to modify the constructor to be "axis-like" aware and convert a single axis automatically to an iterable with a single axis first.
The reason why I think it's fine to do is because the intention of AxesTuple(axis1)
will always be actually AxesTuple([axis1])
.
Alternatively, this could just error when constructing the AxesTuple
Or what do you think?
Steps to reproduce
import boost_histogram as bh
axis1 = hist.axis.Regular(50, -5, 5)
axes = bh.axis.AxesTuple([axis1]) # correct way, works
axes_wrong = bh.axis.AxesTuple(axis1) # wrong! But does not throw an error here
# THIS will error
axes_wrong.edges # or any other attribute