Skip to content

[BUG] (Discussion) Input validation/preprocessing in AxesTuple #678

@jonas-eschle

Description

@jonas-eschle

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions