request for code change in functions.py

31 views
Skip to first unread message

Peter Spuhler

unread,
Oct 17, 2016, 6:48:22 PM10/17/16
to pyqtgraph
line 828 in functions.py
currently
d2 *= scale

propose change to 
d2 = d2 * scale

otherwise will fail to convert types when scale and d2 are not of the same type

for example 

d2 = np.array(1)
scale = np.array(1.0)

results in 
d2 *= scale
Traceback (most recent call last):
  Python Shell, prompt 16, line 1
TypeError: Cannot cast ufunc multiply output from dtype('float64') to dtype('int32') with casting rule 'same_kind'

whereas 
d2 = d2 *scale 
works just fine

Kevin Nielson

unread,
Oct 19, 2016, 3:38:51 PM10/19/16
to pyqtgraph
This appears to have been fixed in the `develop` branch; the line you reference (which is line 870 in 'develop') is now preceded by subtraction of a floating point number:

   869     d2 = data - float(offset)
   870     d2 *= scale
This will automatically promote d2 to a floating point type which will have no issue with *= assignment.

Peter Spuhler

unread,
Oct 19, 2016, 5:27:42 PM10/19/16
to pyqtgraph
Thanks.
Reply all
Reply to author
Forward
0 new messages