enthought / scimath

Other
67 stars 16 forks source link

Bug/feature request: convert/convert_unitted #49

Open jonathanrocher opened 7 years ago

jonathanrocher commented 7 years ago

[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 commented 5 years ago

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.