Hi,
i just committed a fix for issue #135, which is about timedelta rounding.
The problem was in drange:
before the fix it used numpy.arange which resulted in rounding issues,
the numpy doc says about arange:
"When using a non-integer step, such as 0.1, the results will often not
be consistent. It is better to use linspace for these cases."
So i tried to create a fix involving linspace,
you can see it here:
https://github.com/faucon/matplotlib/commit/06195c35f4348f37002e850d1cee992d07f5a29c
it works (and is the only way i found to avoid the roundig issues) but
it feels somehow "hackish".
An alternative would be the following implementation, which is quite
readable but much slower:
def drange(dstart, dend, delta): # its very slow
"""
Return a date range as float Gregorian ordinals. *dstart* and
*dend* are :class:`datetime` instances. *delta* is a
:class:`datetime.timedelta` instance.
"""
dloop = dstart
datelist = []
while dloop < dend:
datelist.append(dloop)
dloop += delta
return dates.date2num(datelist)
i will try to add a test the next days. Then i would create a
pull-request if the fix looks reasonable to you.
thanks,
Maximilian
Thanks for patching. I haven't tested it yet, but the linspace
solution is probably the best way to go. I would avoid drange because
I believe numpy will soon be implementing such a function and I
wouldn't want the possible confusion that comes from that.
Ben Root
···
On Wednesday, July 6, 2011, Maximilian Trescher <faucon@...929...> wrote:
Hi,
i just committed a fix for issue #135, which is about timedelta rounding.
The problem was in drange:
before the fix it used numpy.arange which resulted in rounding issues,
the numpy doc says about arange:
"When using a non-integer step, such as 0.1, the results will often not
be consistent. It is better to use linspace for these cases."
So i tried to create a fix involving linspace,
you can see it here:
fix for issue #135. Workaround for rounding problems · faucon/matplotlib@06195c3 · GitHub
it works (and is the only way i found to avoid the roundig issues) but
it feels somehow "hackish".
An alternative would be the following implementation, which is quite
readable but much slower:
def drange(dstart, dend, delta): # its very slow
"""
Return a date range as float Gregorian ordinals. *dstart* and
*dend* are :class:`datetime` instances. *delta* is a
:class:`datetime.timedelta` instance.
"""
dloop = dstart
datelist =
while dloop < dend:
datelist.append(dloop)
dloop += delta
return dates.date2num(datelist)
i will try to add a test the next days. Then i would create a
pull-request if the fix looks reasonable to you.
thanks,
Maximilian