Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in matplotlib with datetime64 with pandas 0.21.0 #9771

m0nhawk opened this issue Nov 13, 2017 · 2 comments


None yet
3 participants
Copy link

commented Nov 13, 2017

With pandas 0.21 this code with plotting datetime64 fails:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

fig, sub = plt.subplots()
x = np.array(['2015-07-13T04:32:23+0200', '2015-07-13T04:32:24+0200', '2015-07-13T04:32:25+0200'], dtype="datetime64")
y = np.arange(len(x))
sub.plot(x, y)
sub.set_xlim(xmin=x[0], xmax=x[-1])
TypeError                                 Traceback (most recent call last)
<ipython-input-4-483d578e8eb2> in <module>()
      7 y = np.arange(len(x))
      8 sub.plot(x, y)
----> 9 sub.set_xlim(xmin=x[0], xmax=x[-1])

~\Anaconda3\lib\site-packages\matplotlib\axes\ in set_xlim(self, left, right, emit, auto, **kw)
   2917                  'in singular transformations; automatically expanding.\n'
   2918                  'left=%s, right=%s') % (left, right))
-> 2919         left, right = mtransforms.nonsingular(left, right, increasing=False)
   2921         if self.get_xscale() == 'log' and (left <= 0.0 or right <= 0.0):

~\Anaconda3\lib\site-packages\matplotlib\ in nonsingular(vmin, vmax, expander, tiny, increasing)
   2892     close to zero, it returns -*expander*, *expander*.
   2893     '''
-> 2894     if (not np.isfinite(vmin)) or (not np.isfinite(vmax)):
   2895         return -expander, expander

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

While 0.20.3 works fine and produces the result.

I'm not sure if it is a matplotlib or pandas.

Issue in pandas: #18267

@m0nhawk m0nhawk changed the title Error with datetime64 with `pandas` 0.21.0 Error in matplotlib with datetime64 with pandas 0.21.0 Nov 13, 2017

@story645 story645 added the Duplicate label Nov 13, 2017


This comment has been minimized.

Copy link

commented Nov 13, 2017

Pretty sure this is the issue being discussed in #9610. Basically pandas no longer autoregisters their convertors, so everything relying on them breaks. You should be able to fix it by putting this at the top of your code:

from pandas.plotting import _converter
_converter.register()  # needs to override so set_xlim works with str/number

@story645 story645 closed this Nov 13, 2017


This comment has been minimized.

Copy link

commented Nov 13, 2017

Note that the currently recommended way it a slightly different import:

from pandas.tseries import converter

(although I personally think the plotting submodule would be a better place)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.