divmod returns empty tuple sometimes?

Hello,

Using 0.87.4, I'm getting this traceback with a date plot:

/usr/local/stow/matplotlib-0.87.4/lib/python2.4/site-packages/matplotlib/dates.py in _from_ordinalf(x, tz)
    154 dt = datetime.datetime.fromordinal(ix)
    155 remainder = x - ix
--> 156 hour, remainder = divmod(24*remainder, 1)
    157 minute, remainder = divmod(60*remainder, 1)
    158 second, remainder = divmod(60*remainder, 1)

ValueError: need more than 0 values to unpack

/usr/local/stow/matplotlib-0.87.4/lib/python2.4/site-packages/matplotlib/dates.py(156)_from_ordinalf()

    155 remainder = x - ix
--> 156 hour, remainder = divmod(24*remainder, 1)
    157 minute, remainder = divmod(60*remainder, 1)

And sure enough,
    > divmod(0.0,1)
    (0.0, 0.0)
    > divmod( 24*remainder, 1 )
    ()

It looks like divmod is getting overloaded (?) or something in
CXX/cxx_extensions.cxx with [perhaps] this code:

    Py::Object PythonExtensionBase::number_divmod( const Py::Object & )
        { missing_method( number_divmod ); return Py::Nothing(); }

which would make sense, but I haven't explored it that thoroughly. I
think what's happening is that I've got a numpy array scalar that is
sneaking in there somewhere.

For now, I'll just use the hack-fix of casting remainder to a float.

Thanks,
Glen

Glen,
Funny, I ran into exactly the same problem earlier that week. My guess is that
you use numpy, right ? 0.9.8 ? On a 64b machine ?

If that's the case, you should have the same problem with divmod and numpy
each time you use float64 as dtype: each element is a float64scalar that
divmod doesn't know how to process. Downcasting to float32 does the trick
(either by forcing it as dtype, or using a python float().

According to the numpy list, the problem has been corrected in the SVN
version. As I didn't want to install the SVN version yet, I found this
workaround with matplotlib:

in matplotlib/dates.py, change line 155 from
remainder = x - ix
to
remainder = float(x) - ix

That's enough to force the conversion float64scalar to float.