[egenix-users] mx.DateTime 3.2.x and numpy

Christian Marquardt christian at marquardt.sc
Mon Dec 12 00:17:03 CET 2011


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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: mx_problem.py
Type: text/x-python
Size: 264 bytes
Desc: not available
Url : /mailman-archives/egenix-users/attachments/20111212/739737d1/mx_problem.py

More information about the egenix-users mailing list