import pandas as pd
s = pd.Series(np.arange(10.))
rng = pd.date_range('2012-12-12', periods=10, freq='H')
ts = pd.Series(np.arange(10.), index=rng)
ts.plot() and s.plot() work fine
now, if I replace one value with an NaN
ts[2] = np.NaN
ts.plot() give the following error:
File "C:\Python27\lib\site-packages\pandas\core\series.py", line 981, in reshape return ndarray.reshape(self, newshape, order)
It I do ts[2] = np.inf, ts.plot() works...
2 things -
1. If this issue isn't resolved, it's fine to reopen it.
2. Can you post the full traceback of that last error? That would make it much easier to determine what's going on...
In [19]: x
Out[19]:
0 2009-07-31 00:00:00
1 2010-01-10 00:00:00
2 NaT
3 2010-07-31 00:00:00
4 2011-10-10 00:00:00
dtype: datetime64[ns]
In [20]: y=pd.Series(data=x.index, index=x.values)
In [21]: y
Out[21]:
2009-07-31 0
2010-01-10 1
NaT 2
2010-07-31 3
2011-10-10 4
dtype: int64
Traceback (most recent call last):
File "<ipython-input-22-2d08882c171f>", line 1, in <module>
y.plot()
File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 1730, in plot_series
plot_obj.generate()
File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 856, in generate
self._make_plot()
File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 1268, in _make_plot
newline = plotf(*args, **kwds)[0]
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 4138, in plot
self.add_line(line)
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 1497, in add_line
self._update_line_limits(line)
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 1508, in _update_line_limits
path = line.get_path()
File "C:\Python27\lib\site-packages\matplotlib\lines.py", line 743, in get_path
self.recache()
File "C:\Python27\lib\site-packages\matplotlib\lines.py", line 420, in recache
x = np.asarray(xconv, np.float_)
File "C:\Python27\lib\site-packages\numpy\core\numeric.py", line 320, in asarray
return array(a, dtype, copy=False, order=order)
TypeError: float() argument must be a string or a number
My conclusions;
1. Using of NaT Series to Series.index can be good if one uses the pd.to_date() method. Other method produce strange results
2. NaT values in Series.index are not properly handled with pandas plot() function
3. Error may already be caused by funny matplotlib behavior
Do you mean pandas' NaT(datetime) or literal nan (float)?
Do you mean pandas' NaT(datetime) or literal nan (float)?
t = pd.DatetimeIndex( ['2013-01-01', '2013-01-02', '2013-01-03', None, '2013-01-05', '2013-01-06', '2013-01-07'] ) #None becomes NAT in the index. plt.plot(t, y) #this works but the actual drawing raises an exception. plt.draw() #raises an exceptionThe issue using bare matplotlib is actually to be expected, the functions in matplotlib.dates always expect valid dates an do not deal with any kind of NA values.
pd.Series(data=y, index=t).plot() #raises an exception
See the linked notebook for backtraces
http://nbviewer.ipython.org/7300408