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\_base.py 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)
2920
2921 if self.get_xscale() == 'log' and (left <= 0.0 or right <= 0.0):
~\Anaconda3\lib\site-packages\matplotlib\transforms.py 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
2896
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''
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:
frompandas.plottingimport_converter_converter.register() # needs to override so set_xlim works with str/number
Activity
story645 commented on 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:
jorisvandenbossche commented on Nov 13, 2017
Note that the currently recommended way it a slightly different import:
(although I personally think the plotting submodule would be a better place)