enthought / enthought/scimath

UnitArray __rmul__ and __rdiv__ drop units when isinstance(other, numpy.generic)

Open
#6 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
66
Forks
13
PR merge metrics
No merged PRs in 30d

Description

I have discovered that scimath.units is dropping the units from the result when the left hand operand to \* or / is a numpy scalar. Simple test cases:

``` python
>>> import numpy
>>> from scimath.units.api import UnitArray
>>> from scimath.units import SI
>>> a = UnitArray(1., units=SI.meter)
>>> b = numpy.array(1.)
>>> a*b # This will work
UnitArray(1.0, units='1.0*m')
>>> b*a # This also works
UnitArray(1.0, units='1.0*m')
>>> c = numpy.sqrt(1.)
>>> type(c)

>>> a*c # this, i.e. __mul__ works
UnitArray(1.0, units='1.0*m')
>>> c*a # __rmul__ fails!
UnitArray(1.0, units='None')
>>> c / a # __rdiv__ shows the same bug
UnitArray(1.0, units='None')

```

It is not immediately clear to me how to fix this.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.