Skip to content

Plotting series with different frequency yields "ValueError: Incompatible frequency conversion" #7760

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

Closed
mmajewsk opened this issue Jul 15, 2014 · 1 comment · Fixed by #7803
Labels
Bug Period Period data type Visualization plotting
Milestone

Comments

@mmajewsk
Copy link

So i have two dataframes with simmilar data but, indexed by datetime64
dfA : http://pastebin.com/HenYJxdV
dfB : http://pastebin.com/qAsEqSxf

so i have following problem when i try to plot them this way:

In [107]:

seriesA=dfA["more"]
seriesB=dfB["less"]
In [108]:

plt.figure()
plt.plot(seriesA.index.tolist(),seriesA.tolist())
plt.plot(seriesB.index.tolist(),seriesB.tolist())

it's ok and both series have been plotted on same figure

but when i'll try this:

plt.figure()
seriesA.plot()
seriesB.plot()

it wrecks and i get following output

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-109-5054484e1e31> in <module>()
      1 plt.figure()
      2 seriesA.plot()
----> 3 seriesB.plot()
      4 

C:\winpy\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\lib\site-packages\pandas\tools\plotting.pyc in plot_series(series, label, kind, use_index, rot, xticks, yticks, xlim, ylim, ax, style, grid, legend, logx, logy, secondary_y, **kwds)
   2254                      secondary_y=secondary_y, **kwds)
   2255 
-> 2256     plot_obj.generate()
   2257     plot_obj.draw()
   2258 

C:\winpy\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\lib\site-packages\pandas\tools\plotting.pyc in generate(self)
    900         self._compute_plot_data()
    901         self._setup_subplots()
--> 902         self._make_plot()
    903         self._add_table()
    904         self._make_legend()

C:\winpy\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\lib\site-packages\pandas\tools\plotting.pyc in _make_plot(self)
   1549         if self._is_ts_plot():
   1550             data = self._maybe_convert_index(self.data)
-> 1551             self._make_ts_plot(data)
   1552         else:
   1553             from pandas.core.frame import DataFrame

C:\winpy\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\lib\site-packages\pandas\tools\plotting.pyc in _make_ts_plot(self, data, **kwargs)
   1646             y_values = self._get_stacked_values(y, label)
   1647 
-> 1648             newlines = plotf(y_values, ax, label, style, **kwds)
   1649             self._add_legend_handle(newlines[0], label, index=i)
   1650 

C:\winpy\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\lib\site-packages\pandas\tools\plotting.pyc in _plot(data, ax, label, style, **kwds)
   1623             else:
   1624                 lines = tsplot(data, plotf, ax=ax, label=label,
-> 1625                                style=style, **kwds)
   1626                 return lines
   1627         return _plot

C:\winpy\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\lib\site-packages\pandas\tseries\plotting.pyc in tsplot(series, plotf, **kwargs)
     57             series = series.to_period(freq=freq)
     58         freq, ax_freq, series = _maybe_resample(series, ax, freq, plotf,
---> 59                                                 kwargs)
     60 
     61     # Set ax with freq info

C:\winpy\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\lib\site-packages\pandas\tseries\plotting.pyc in _maybe_resample(series, ax, freq, plotf, kwargs)
    107             ax_freq = freq
    108         else:  # pragma: no cover
--> 109             raise ValueError('Incompatible frequency conversion')
    110     return freq, ax_freq, series
    111 

ValueError: Incompatible frequency conversion

Which is extremely weird because before, i plotted similar but yet slightly different data and it plotted correctly.

P.S. pd.show_versions():

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 37 Stepping 2, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.14.0
nose: 1.3.1
Cython: 0.20.1
numpy: 1.8.1
scipy: 0.13.3
statsmodels: 0.5.0
IPython: 2.0.0
sphinx: 1.2.2
patsy: 0.2.1
scikits.timeseries: None
dateutil: 2.2
pytz: 2013.9
bottleneck: None
tables: 3.1.1
numexpr: 2.3.1
matplotlib: 1.3.1
openpyxl: None
xlrd: 0.9.3
xlwt: 0.7.5
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
bq: None
apiclient: None
rpy2: None
sqlalchemy: 0.9.4
pymysql: None
psycopg2: None
@mmajewsk
Copy link
Author

further investigation revealed that there is a problem with index.inferred_freq which is being set to "100l" and it's done where my code calls df = df.set_index('column_name')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Period Period data type Visualization plotting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants