Skip to content

Improve error message when setting an Array subset with an unlabelled array-like of incorrect shape #1169

@gdementen

Description

@gdementen

Currently users get the raw message from numpy in that case:

>>> import numpy as np
>>> arr = ndtest((2, 3))
>>> arr['a0'] = np.array([1, 2])
ValueError: could not broadcast input array from shape (2,) into shape (3,)

But we could help debugging by providing the labels of the target subset in the error message.

>>> arr['a0'].axes
AxisCollection([
    Axis(['b0', 'b1', 'b2'], 'b')
])

This kind of issue is more frequent than one could think as our users encounter it when loading "raw" (unlabelled) data from Excel via:

>>> with open_excel() as wb:
...     sheet = wb[0]
...     # add some data (no dump => no labels)
...     sheet[:] = ndtest((2, 3))
...     arr['a0'] = sheet['A1:B1']
ValueError: could not broadcast input array from shape (2,) into shape (3,)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions