Skip to content

np.digitize does not convert units when required #633

@kyleaoman

Description

@kyleaoman

Here is a simple illustration:

>>> np.digitize([1.1, 2.2, 3.3] * u.g, [0, 1, 2, 3] * u.kg)
array([2, 3, 4])  # expected array([1, 1, 1])

All input values are more than 0 and less than 1 kg, so should be in bin 1 (note: digitize uses 0 for "outside the bin range below"), but the result is what is expected for input values and bins treated as bare arrays. Similarly, mismatched dimensions are ignored:

>>> np.digitize([1.1,2.2,3.3] * u.g, [0, 1, 2, 3] * u.s)
array([2, 3, 4])  # expected to raise

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