Skip to content

Graceful fallback for unit errors (warning, casting to float/array, etc.) rather than raising UnitOperationError? #165

@mkhorton

Description

@mkhorton

Description

This is a question/feature request, not a bug. If there is a more appropriate place to ask this, please let me know.

We're looking at a way to add comprehensive unit integration into an existing project. This project is already seeing existing use by other downstream code, so we would prefer not to break backwards compatibility abruptly for our users, and would prefer to support a grace period if possible.

Currently, to take an example:

from unyt import Angstrom
a = 3*Angstrom
a + 1  # raises `UnitOperationError`

Is it possible to configure unyt to instead issue a warning here instead of raising and to return a de-unitized value, e.g. for this example to return 4 as a float?

If this is not possible, is there a single place in the unyt code where such a feature could be added?

If this was possible, we would be able to switch to using unyt in our project, but disable strict enforcement of units by default for our users so that we wouldn't break any existing scripts overnight. It'd also allow us to have a more gradual transition period, while simultaneously allowing us to strictly enforce units in our testing and CI and when developing new features.

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