Skip to content

Improve getitem ValueError message when trying to retrieve multiple labels #1101

Closed
@gdementen

Description

@gdementen

When trying to retrieve several labels and it fails, it is sometimes hard to know exactly which label(s) are missing from the array, especially when the axes are long and not all labels are displayed in the axes summary.

I think that when it fails, displaying axes where it matches partially and the missing keys could be a large quality of life improvement:

>>> arr = la.ndtest('a=a0..a4,a6..a9;b=b0..b2')
>>> arr['a0,a7,a2,a5,a3,a4,a8']
ValueError: 'a0,a7,a2,a5,a3,a4,a8' is not a valid label for any axis:
 a [9]: 'a0' 'a1' 'a2' ... 'a7' 'a8' 'a9'
 b [3]: 'b0' 'b1' 'b2'

FWIW, as a quick workaround, I had to resort to this to know which key was missing:

>>> arr.a.union('a0,a7,a2,a5,a3,a4,a8').difference(arr.a)
Axis(['a5'], 'a')

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions