Skip to content

Fix automatic bin-edge finding when coord has nan value #3506

@jokasimr

Description

@jokasimr

If no explicit bin-edges are passed to the .bin method scipp tries to determine suitable bin-edges based on the values of the coordinate.

If the coordinate has nan values this fails

import scipp as sc
data = sc.data.table_xyz(10)
data.coords['x'][0] = sc.scalar(float('nan'), unit=data.coords['x'].unit)
data.bin(x=4, y=2)

with error BinEdgeError: Bin edges in dim x must be sorted.

The error here is reasonable, we can't construct a binning without dropping the events associated with the nan coord values, and we don't want to do that automatically.
But the error message is not very clear. If we catch this issue before the faulty bin-edges are passed to _cpp.bin we could provide the user with a better error message like: ValueError: coordinate contains nan, could not determine bin edges automatically.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions