Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/feature request: convert/convert_unitted #49

Open
jonathanrocher opened this issue Oct 18, 2016 · 1 comment
Open

Bug/feature request: convert/convert_unitted #49

jonathanrocher opened this issue Oct 18, 2016 · 1 comment

Comments

@jonathanrocher
Copy link
Contributor

[I feel like I have had this conversation before, but can't find trace of it anymore. Hope it is not a duplicate]

I keep forgetting that the convert function only works for float, not UnitScalars. As a result, and because UnitScalar is a subclass of np.ndarray, the following happens:

In [3]: from scimath.units.api import convert, UnitScalar

In [4]: x = UnitScalar(1., units="cm")

In [5]: from scimath.units.length import meter

In [6]: convert(x, from_unit=x.units, to_unit=meter)
Out[6]: UnitScalar(0.01, units='0.01*m')

which feels very buggy. I believe that we should:

  1. either raise an exception when a UnitScalar is passed, and create a new convert_unitted function that accepts UnitScalars/UnitArrays
  2. or support the UnitScalars correctly.

I think I like option 2 better, but it makes things not backward compatible, so is probably a no go.

Opinions? @timdiller @rkern ?

@elena-pascal
Copy link

The @has_units decorated function is converting inputs to the units stated but not the outputs. I'm wondering why. If it were it would be trivial to write a convert function for any UnitScalar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants