Skip to content

check that key is valid on axis[key] #596

@gdementen

Description

@gdementen

Currently, keys are only checked when used in an array, so when creating a group, it happily accepts keys which do not exist.

>>> arr = ndtest((2, 3))
>>> # this should fail
... g = arr.a['yada']
>>> g
a['yada']
>>> arr[g]
ValueError: a['yada'] is not a valid label for any axis

FWIW, it was done this way initially for two reasons:

  1. performance (to avoid translating the key if it is not used), but in the end, it is better to be correct than fast and, in the usual case where the resulting group is actually used, it would be even faster this way (assuming we translate it directly to positional).
  2. to be correct in case the axis labels are modified in-place. But I now think we should either forbid this anyway, or allow this with a big fat warning that you might be shooting yourself in the foot.

related to #200. Please see the comments there.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions