The following codes from 10 Minutes to pandas could not be run properly.
In [135]: ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
In [136]: ts = ts.cumsum()
In [137]: ts.plot()
Problem description
It gives error as follows. Is that caused by some dependency problem or other issues? Thanks.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-154-72917dc50e90> in <module>()
3 ts = ts.cumsum()
4
----> 5 ts.plot()
/home/myubuntu/anaconda2/envs/tensorflow3/lib/python3.5/site-packages/pandas/tools/plotting.py in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3597 colormap=colormap, table=table, yerr=yerr,
3598 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3599 **kwds)
3600 __call__.__doc__ = plot_series.__doc__
3601
/home/myubuntu/anaconda2/envs/tensorflow3/lib/python3.5/site-packages/pandas/tools/plotting.py in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2671 yerr=yerr, xerr=xerr,
2672 label=label, secondary_y=secondary_y,
-> 2673 **kwds)
2674
2675
/home/myubuntu/anaconda2/envs/tensorflow3/lib/python3.5/site-packages/pandas/tools/plotting.py in _plot(data, x, y, subplots, ax, kind, **kwds)
2467 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2468
-> 2469 plot_obj.generate()
2470 plot_obj.draw()
2471 return plot_obj.result
/home/myubuntu/anaconda2/envs/tensorflow3/lib/python3.5/site-packages/pandas/tools/plotting.py in generate(self)
1041 self._compute_plot_data()
1042 self._setup_subplots()
-> 1043 self._make_plot()
1044 self._add_table()
1045 self._make_legend()
/home/myubuntu/anaconda2/envs/tensorflow3/lib/python3.5/site-packages/pandas/tools/plotting.py in _make_plot(self)
1724 stacking_id=stacking_id,
1725 is_errorbar=is_errorbar,
-> 1726 **kwds)
1727 self._add_legend_handle(newlines[0], label, index=i)
1728
/home/myubuntu/anaconda2/envs/tensorflow3/lib/python3.5/site-packages/pandas/tools/plotting.py in _ts_plot(cls, ax, x, data, style, **kwds)
1762 ax._plot_data.append((data, cls._kind, kwds))
1763
-> 1764 lines = cls._plot(ax, data.index, data.values, style=style, **kwds)
1765 # set date formatter, locators and rescale limits
1766 format_dateaxis(ax, ax.freq)
/home/myubuntu/anaconda2/envs/tensorflow3/lib/python3.5/site-packages/pandas/tools/plotting.py in _plot(cls, ax, x, y, style, column_num, stacking_id, **kwds)
1739 cls._initialize_stacker(ax, stacking_id, len(y))
1740 y_values = cls._get_stacked_values(ax, stacking_id, y, kwds['label'])
-> 1741 lines = MPLPlot._plot(ax, x, y_values, style=style, **kwds)
1742 cls._update_stacker(ax, stacking_id, y)
1743 return lines
/home/myubuntu/anaconda2/envs/tensorflow3/lib/python3.5/site-packages/pandas/tools/plotting.py in _plot(cls, ax, x, y, style, is_errorbar, **kwds)
1359 else:
1360 args = (x, y)
-> 1361 return ax.plot(*args, **kwds)
1362
1363 def _get_index_name(self):
/home/myubuntu/anaconda2/envs/tensorflow3/lib/python3.5/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
1817 warnings.warn(msg % (label_namer, func.__name__),
1818 RuntimeWarning, stacklevel=2)
-> 1819 return func(ax, *args, **kwargs)
1820 pre_doc = inner.__doc__
1821 if pre_doc is None:
/home/myubuntu/anaconda2/envs/tensorflow3/lib/python3.5/site-packages/matplotlib/axes/_axes.py in plot(self, *args, **kwargs)
1381
1382 for line in self._get_lines(*args, **kwargs):
-> 1383 self.add_line(line)
1384 lines.append(line)
1385
/home/myubuntu/anaconda2/envs/tensorflow3/lib/python3.5/site-packages/matplotlib/axes/_base.py in add_line(self, line)
1701 line.set_clip_path(self.patch)
1702
-> 1703 self._update_line_limits(line)
1704 if not line.get_label():
1705 line.set_label('_line%d' % len(self.lines))
/home/myubuntu/anaconda2/envs/tensorflow3/lib/python3.5/site-packages/matplotlib/axes/_base.py in _update_line_limits(self, line)
1723 Figures out the data limit of the given line, updating self.dataLim.
1724 """
-> 1725 path = line.get_path()
1726 if path.vertices.size == 0:
1727 return
/home/myubuntu/anaconda2/envs/tensorflow3/lib/python3.5/site-packages/matplotlib/lines.py in get_path(self)
936 """
937 if self._invalidy or self._invalidx:
--> 938 self.recache()
939 return self._path
940
/home/myubuntu/anaconda2/envs/tensorflow3/lib/python3.5/site-packages/matplotlib/lines.py in recache(self, always)
623 x = ma.asarray(xconv, np.float_).filled(np.nan)
624 else:
--> 625 x = np.asarray(xconv, np.float_)
626 x = x.ravel()
627 else:
/home/myubuntu/anaconda2/envs/tensorflow3/lib/python3.5/site-packages/numpy/core/numeric.py in asarray(a, dtype, order)
480
481 """
--> 482 return array(a, dtype, copy=False, order=order)
483
484 def asanyarray(a, dtype=None, order=None):
TypeError: float() argument must be a string or a number, not 'Period'
Output of pd.show_versions()
Comment From: jorisvandenbossche
This is a strange error. The docs examples are executed at build time, so the example works, and I also cannot reproduce this. Are you able to reproduce this in a clean python session?
Comment From: keshavramaswamy
I am able to reproduce this - in both Python 2.7 and Python 3.5
Comment From: jorisvandenbossche
@keshavramaswamy Thanks for testing. Can you show the full output of the session (input and error traceback) and the output of pd.show_versions
for each of them?
Comment From: jorisvandenbossche
@hiiwave Can you also try if you can reproduce this with a clean conda env? I see you are using that, so simply doing something like this:
conda create -n test-pandas-bug python=3 pandas matplotlib
source activate test-pandas-bug
python
... [breaking code]
to see if that reproduces the error.
Comment From: hiiwave
Thanks for your concern. Since I'm on a vacation, I'll try it once I'm back.
Comment From: keshavramaswamy
Sure @jorisvandenbossche - To clarify - I was able to generate the plots in both Python 2.7 and Python 3.5
Here is the output of pd.show_versions
for each of them:
Python 3.5 INSTALLED VERSIONS
commit: None python: 3.5.2.final.0 python-bits: 64 OS: Darwin OS-release: 15.6.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8
pandas: 0.19.1 nose: 1.3.7 pip: 9.0.1 setuptools: 27.2.0 Cython: 0.24.1 numpy: 1.11.1 scipy: 0.18.1 statsmodels: 0.6.1 xarray: None IPython: 5.1.0 sphinx: 1.4.6 patsy: 0.4.1 dateutil: 2.5.3 pytz: 2016.6.1 blosc: None bottleneck: 1.1.0 tables: 3.2.3.1 numexpr: 2.6.1 matplotlib: 1.5.3 openpyxl: 2.3.2 xlrd: 1.0.0 xlwt: 1.1.2 xlsxwriter: 0.9.3 lxml: 3.6.4 bs4: 4.5.1 html5lib: None httplib2: None apiclient: None sqlalchemy: 1.0.13 pymysql: None psycopg2: None jinja2: 2.8 boto: 2.42.0 pandas_datareader: None
Python 2.7 INSTALLED VERSIONS
commit: None python: 2.7.12.final.0 python-bits: 64 OS: Darwin OS-release: 15.6.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: None.None
pandas: 0.19.1 nose: None pip: 9.0.1 setuptools: 27.2.0 Cython: None numpy: 1.11.2 scipy: None statsmodels: None xarray: None IPython: 5.1.0 sphinx: None patsy: None dateutil: 2.6.0 pytz: 2016.10 blosc: None bottleneck: None tables: None numexpr: None matplotlib: 1.5.3 openpyxl: None xlrd: None xlwt: None xlsxwriter: None lxml: None bs4: None html5lib: None httplib2: None apiclient: None sqlalchemy: None pymysql: None psycopg2: None jinja2: 2.8 boto: None pandas_datareader: None
Comment From: jorisvandenbossche
@keshavramaswamy Thanks. Are the error tracebacks exactly the same as in the top post? Are you using conda? If so, could you post the full output from creating a new clean env with just pandas and matplotlib, running the code, and the error traceback?
Comment From: keshavramaswamy
@jorisvandenbossche So, I am able to generate the plots - There are no errors generated when I run them on my machine.
Comment From: jorisvandenbossche
@keshavramaswamy Ah, sorry, missed that in your previous post. I misunderstood the "I am able to reproduce this" from before :-)
Comment From: keshavramaswamy
Yeah that's my bad - should have made it clear in the first place!
On Thu, Dec 15, 2016 at 11:24 AM Joris Van den Bossche notifications@github.com wrote:
@keshavramaswamy https://github.com/keshavramaswamy Ah, sorry, missed that in your previous post. I misunderstood the "I am able to reproduce this" from before :-)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pandas-dev/pandas/issues/14838#issuecomment-267371432, or mute the thread https://github.com/notifications/unsubscribe-auth/AGg1E7emuEABl02yj2lC_fBkDA68_ymEks5rIWmpgaJpZM4LJAGH .
Comment From: hiiwave
Hi. I tried it today but failed to reproduce my reported problem and I have no idea why so. Let's close this issue now and reopen it if needed one day. Thanks.
Comment From: khwilson-dc
This isn't super useful knowledge, but I just had this error on a fresh install of jupyter, numpy, scipy, pandas, and matplotlib on newly brew installed version of python3.6. When I restarted Jupyter it went away.
In the traceback, time_counts
is a series with a DateTimeIndex
and int64
values. pd.show_versions()
after the traceback.
Traceback:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-43-e4ad26e8628d> in <module>()
1 hourly_counts = time_counts.resample('H').sum()
----> 2 hourly_counts.plot()
/usr/local/lib/python3.6/site-packages/pandas/tools/plotting.py in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3598 colormap=colormap, table=table, yerr=yerr,
3599 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3600 **kwds)
3601 __call__.__doc__ = plot_series.__doc__
3602
/usr/local/lib/python3.6/site-packages/pandas/tools/plotting.py in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2672 yerr=yerr, xerr=xerr,
2673 label=label, secondary_y=secondary_y,
-> 2674 **kwds)
2675
2676
/usr/local/lib/python3.6/site-packages/pandas/tools/plotting.py in _plot(data, x, y, subplots, ax, kind, **kwds)
2468 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2469
-> 2470 plot_obj.generate()
2471 plot_obj.draw()
2472 return plot_obj.result
/usr/local/lib/python3.6/site-packages/pandas/tools/plotting.py in generate(self)
1041 self._compute_plot_data()
1042 self._setup_subplots()
-> 1043 self._make_plot()
1044 self._add_table()
1045 self._make_legend()
/usr/local/lib/python3.6/site-packages/pandas/tools/plotting.py in _make_plot(self)
1724 stacking_id=stacking_id,
1725 is_errorbar=is_errorbar,
-> 1726 **kwds)
1727 self._add_legend_handle(newlines[0], label, index=i)
1728
/usr/local/lib/python3.6/site-packages/pandas/tools/plotting.py in _ts_plot(cls, ax, x, data, style, **kwds)
1762 ax._plot_data.append((data, cls._kind, kwds))
1763
-> 1764 lines = cls._plot(ax, data.index, data.values, style=style, **kwds)
1765 # set date formatter, locators and rescale limits
1766 format_dateaxis(ax, ax.freq)
/usr/local/lib/python3.6/site-packages/pandas/tools/plotting.py in _plot(cls, ax, x, y, style, column_num, stacking_id, **kwds)
1739 cls._initialize_stacker(ax, stacking_id, len(y))
1740 y_values = cls._get_stacked_values(ax, stacking_id, y, kwds['label'])
-> 1741 lines = MPLPlot._plot(ax, x, y_values, style=style, **kwds)
1742 cls._update_stacker(ax, stacking_id, y)
1743 return lines
/usr/local/lib/python3.6/site-packages/pandas/tools/plotting.py in _plot(cls, ax, x, y, style, is_errorbar, **kwds)
1359 else:
1360 args = (x, y)
-> 1361 return ax.plot(*args, **kwds)
1362
1363 def _get_index_name(self):
/usr/local/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
1890 warnings.warn(msg % (label_namer, func.__name__),
1891 RuntimeWarning, stacklevel=2)
-> 1892 return func(ax, *args, **kwargs)
1893 pre_doc = inner.__doc__
1894 if pre_doc is None:
/usr/local/lib/python3.6/site-packages/matplotlib/axes/_axes.py in plot(self, *args, **kwargs)
1405
1406 for line in self._get_lines(*args, **kwargs):
-> 1407 self.add_line(line)
1408 lines.append(line)
1409
/usr/local/lib/python3.6/site-packages/matplotlib/axes/_base.py in add_line(self, line)
1785 line.set_clip_path(self.patch)
1786
-> 1787 self._update_line_limits(line)
1788 if not line.get_label():
1789 line.set_label('_line%d' % len(self.lines))
/usr/local/lib/python3.6/site-packages/matplotlib/axes/_base.py in _update_line_limits(self, line)
1807 Figures out the data limit of the given line, updating self.dataLim.
1808 """
-> 1809 path = line.get_path()
1810 if path.vertices.size == 0:
1811 return
/usr/local/lib/python3.6/site-packages/matplotlib/lines.py in get_path(self)
987 """
988 if self._invalidy or self._invalidx:
--> 989 self.recache()
990 return self._path
991
/usr/local/lib/python3.6/site-packages/matplotlib/lines.py in recache(self, always)
674 x = ma.asarray(xconv, np.float_).filled(np.nan)
675 else:
--> 676 x = np.asarray(xconv, np.float_)
677 x = x.ravel()
678 else:
/usr/local/lib/python3.6/site-packages/numpy/core/numeric.py in asarray(a, dtype, order)
529
530 """
--> 531 return array(a, dtype, copy=False, order=order)
532
533
TypeError: float() argument must be a string or a number, not 'Period'
pd.show_versions
INSTALLED VERSIONS
commit: None python: 3.6.0.final.0 python-bits: 64 OS: Darwin OS-release: 15.6.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LOCALE: en_US.UTF-8
pandas: 0.19.2 nose: None pip: 9.0.1 setuptools: 32.2.0 Cython: None numpy: 1.12.0 scipy: 0.18.1 statsmodels: None xarray: None IPython: 5.3.0 sphinx: None patsy: None dateutil: 2.6.0 pytz: 2016.10 blosc: None bottleneck: None tables: None numexpr: None matplotlib: 2.0.0 openpyxl: None xlrd: None xlwt: None xlsxwriter: None lxml: None bs4: None html5lib: 0.9999999 httplib2: None apiclient: None sqlalchemy: None pymysql: None psycopg2: None jinja2: 2.9.5 boto: None pandas_datareader: None