datetutil issues

I'm doing some date plotting and make use of dateutil. The version
I have is given as 1.2-mpl and I believe it installed directly with the
latest matplotlib installation.

My problem is with dateutil's microsecond precision. An example:

date = '2009-01-11 03:55:23.255000'
d = dateutil.parser.parse(date)
d

datetime.datetime(2009, 1, 11, 3, 55, 23, 254999)

Note the microseconds of the datetime object are 254999,
whereas the original date string given was 255000. This matters
to me in that I am matching to a database and would prefer to
have the two values just match without further manipulation.

I thought maybe newer versions of dateutil would have had this
issue worked out. I see there is a dateutil 1.4.1 available, here:
http://labix.org/python-dateutil

But I can't seem to install it. If I go into its downloaded directory
and in the Win command line write "python setup.py install"
it complains "No module named setuptools". (I can usually
install things in this way fine).

Can anyone help me out? And can matplotlib include the
more updated version of dateutil in its future releases?

Thanks,
Che

I'm doing some date plotting and make use of dateutil. The version
I have is given as 1.2-mpl and I believe it installed directly with the
latest matplotlib installation.

My problem is with dateutil's microsecond precision. An example:

date = '2009-01-11 03:55:23.255000'
d = dateutil.parser.parse(date)
d

datetime.datetime(2009, 1, 11, 3, 55, 23, 254999)

Note the microseconds of the datetime object are 254999,
whereas the original date string given was 255000. This matters
to me in that I am matching to a database and would prefer to
have the two values just match without further manipulation.

I thought maybe newer versions of dateutil would have had this
issue worked out. I see there is a dateutil 1.4.1 available, here:
http://labix.org/python-dateutil

Yes it's fixed:

$ python
Python 2.5.2 (r252:60911, Jan 4 2009, 21:59:32)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import dateutil.parser
dateutil.__version__

'1.4.1'

date = '2009-01-11 03:55:23.255000'
d = dateutil.parser.parse(date)
d

datetime.datetime(2009, 1, 11, 3, 55, 23, 255000)

Regards,

···

On Mon, Feb 2, 2009 at 20:29, C M <cmpython@...287...> wrote:
--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi

My problem is with dateutil's microsecond precision. An example:

date = '2009-01-11 03:55:23.255000'
d = dateutil.parser.parse(date)
d

datetime.datetime(2009, 1, 11, 3, 55, 23, 254999)

Note the microseconds of the datetime object are 254999,
whereas the original date string given was 255000.

Just in case anyone is curios, this is a classic binary floating point issue:

the 23.2550000 is being interpreted as floating point seconds, rather than as integer seconds and microseconds. 23.255 can not be exactly represented in binary floating point:

>>> s = 23.255000
>>> s
23.254999999999999
>>>

>>> s - int(s)
0.25499999999999901
>>>

I suspect dateutils is fixed by either parsing out the seconds, or adding a round() to the above:

>>> s = 23.255
>>> seconds = int(s)
>>> microseconds = int(round((s-seconds)*1e6))
>>> seconds, microseconds
(23, 255000)

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...