Skip to content

Plotting Series/DF of dtype object fails intermittently #3108

@patricktokeeffe

Description

@patricktokeeffe

There seems to be an intermittent issue which prevents plotting Series/DataFrames with dtype object. See traceback below. This manifests for me when reading data from files but not when manually creating dataframes from the command line. It can be worked around by explicitly casting to float64. The presence of NANs does not appear to have an effect.

>>> df = pd.read_csv('data.csv') # CSV data file with some "NAN" entries >>> df['chan1'].dtype dtype('object') >>> df['chan1'].plot() # fails >>> df['chan1'].dropna().plot() # fails >>> df['chan1'].apply(float).plot() # works >>> df['chan1'].dropna().apply(float).plot() # works

This works though:

df = pd.DataFrame([3, 1, 4, np.nan, 5, 9], dtype=object) # works df = pd.DataFrame([3, 1, 4, "NAN", 5, 9], dtype=object) # works df = pd.DataFrame([3, 1, 4, 1, 5, 9], dtype=object) # works

Here is the traceback; it is the same as encountered in #478 and presumably in #1818. Note it doesn't include the error message added in 9186cbc

>>> df = pd.read_csv(r'C:\test\stats.dat') >>> df['Ts_Avg'].plot() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\WinPython-64bit-2.7.3.3\python-2.7.3.amd64\lib\site-packages\pandas\tools\plotting.py", line 1534, in plot_series plot_obj.generate() File "C:\WinPython-64bit-2.7.3.3\python-2.7.3.amd64\lib\site-packages\pandas\tools\plotting.py", line 735, in generate self._make_plot() File "C:\WinPython-64bit-2.7.3.3\python-2.7.3.amd64\lib\site-packages\pandas\tools\plotting.py", line 1106, in _make_plot newline = plotf(*args, **kwds)[0] File "C:\WinPython-64bit-2.7.3.3\python-2.7.3.amd64\lib\site-packages\matplotlib\axes.py", line 3996, in plot for line in self._get_lines(*args, **kwargs): File "C:\WinPython-64bit-2.7.3.3\python-2.7.3.amd64\lib\site-packages\matplotlib\axes.py", line 330, in _grab_next_args for seg in self._plot_args(remaining, kwargs): File "C:\WinPython-64bit-2.7.3.3\python-2.7.3.amd64\lib\site-packages\matplotlib\axes.py", line 289, in _plot_args linestyle, marker, color = _process_plot_format(tup[-1]) File "C:\WinPython-64bit-2.7.3.3\python-2.7.3.amd64\lib\site-packages\matplotlib\axes.py", line 96, in _process_plot_format if fmt.find('--')>=0: AttributeError: 'numpy.ndarray' object has no attribute 'find'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions