[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] returning numpy numbers in QVariant
From: Jeremy Sanders <jeremy () jeremysanders ! net>
Date: 2010-04-23 13:08:39
Message-ID: hqs64o$5qm$1 () dough ! gmane ! org
[Download RAW message or body]
Phil Thompson wrote:
> Are numpy numbers regular ints/floats or are they a sub-class specific to
> numpy?
>
> QVariant has been changed (over time) to make sure that no information is
> lost when converting from and to the original object. So an int sub-class
> will stay as a Python object and will not get converted to a C++ int.
>
> If this is the problem then the fix is to explicitly convert the numpy
> number to a base Python type before converting to a QVariant...
>
> return QVariant(float(a[0]))
>
> ...and this will work for older versions as well.
That workaround works well - thanks.
numpy numbers have their own type (there are actually several types as you
can choose the precision), so that's probably what causes the QVariant
problems:
In [1]: import numpy
In [2]: a = numpy.array([1.])
In [3]: type(a[0])
Out[3]: <type 'numpy.float64'>
Jeremy
--
http://www.jeremysanders.net/
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic