mx.DateTime 3.2.x and numpy
Christian Marquardt <[email protected]> Mon, 12 Dec 2011 00:17:03 +0100 (CET)
| Newsgroups | gmane.comp.python.egenix.user |
|---|---|
| Message-ID | <15145075.339.1323645423254.JavaMail.root@athene> |
Hello,
I hope this is the right place to ask this question...
We are in the process of upgrading our mx.Base installation from 3.1.3 to 3.2.1, and while testing, we ran into a problem with the following script (which is also attached)::
import numpy as np
import mx.DateTime as dt
print "Numpy version: ", np.__version__
print "DateTime version:", dt.__version__
delta_t = np.arange(5) * dt.oneHour
t0 = dt.now()
t = t0 + delta_t
print t
For mx.DateTime v3.1.3 (was the version string ever updated in the release?), the output is as expected:
TCLXS9 (mx) /homespace/marq/python/work/mx>python ../object_arrays/mx_problem.py
Numpy version: 1.5.1
DateTime version: 3.1.2
[2011-12-11 22:39:38.60 2011-12-11 23:39:38.60 2011-12-12 00:39:38.60
2011-12-12 01:39:38.60 2011-12-12 02:39:38.60]
i.e. the addition of a single mx.DateTime object and a numpy array of mx.DateTimeDelta objects just works. But in v3.2.0 and later, we get
TCLXS9 (mx) /homespace/marq/python/work/mx>python ../object_arrays/mx_problem.py
Numpy version: 1.5.1
DateTime version: 3.2.1
Traceback (most recent call last):
File "../object_arrays/mx_problem.py", line 12, in <module>
t = t0 + delta_t
TypeError: only length-1 arrays can be converted to Python scalars
This is independent from the numpy version (it fails with the more recent numpy 1.6.1 as well), so I think the problem is in mx.DateTime. It also surfaces in other circumstances, for example when trying to compare as scalar mx.DateTime object with an array of such objects.
A workaround is to wrap the mx.DateTime scalar in an np.asarray() - but I think it's a bug anyway - and we have a large number of uses cases like the two described, so I would prefer if there would be a way to fix it within mx.DateTime.
Any ideas what introduced this bug in 3.2.0?
Many thanks,
Christian.
_______________________________________________________________________
eGenix.com User Mailing List http://www.egenix.com/
https://www.egenix.com/mailman/listinfo/egenix-users
mx_problem.py
(text/x-python, 264 B)
# Demonstrates mx.DateTime problem in numpy 1.6.1 import numpy as np import mx.DateTime as dt print "Numpy version: ", np.__version__ print "DateTime version:", dt.__version__ delta_t = np.arange(5) * dt.oneHour t0 = dt.now() t = t0 + delta_t print t