BUG: Series.plot() doesn't work with CustomBusinessDay frequency #7222

Closed
seth-p opened this Issue May 23, 2014 · 8 comments

Comments

Projects
None yet
6 participants
Contributor

seth-p commented May 23, 2014

I posted this on https://groups.google.com/forum/#!topic/pydata/FnHBkkdBIFY.

In IPython, trying to .plot() a Series with a CustomBusinessDay frquency produces "ValueError: Unknown freqstr: C". See below. I imagine DataFrame.plot() would have a similar issue.

Am running http://pandas.pydata.org/pandas-build/dev/pandas-0.14.0rc1-51-gccd593f.win-amd64-py3.4.exe and matplotlib 1.2.0.

import pandas as pd

from pandas.tseries.offsets import CustomBusinessDay



s = pd.Series(range(100, 121),
              index=pd.bdate_range(start='2014-05-01', end='2014-06-01',
                                   freq=CustomBusinessDay(holidays=['2014-05-26'])))

s.plot()

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-8a6b3fabc67e> in <module>()
      3 
      4 s = pd.Series(range(100,121), index=pd.bdate_range(start='2014-05-01', end='2014-06-01', freq=CustomBusinessDay(holidays=['2014-05-26'])))
----> 5 s.plot()

C:\Python34\lib\site-packages\pandas\tools\plotting.py 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:\Python34\lib\site-packages\pandas\tools\plotting.py 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:\Python34\lib\site-packages\pandas\tools\plotting.py in _make_plot(self)
   1547         self._neg_prior = np.zeros(len(self.data))
   1548 
-> 1549         if self._is_ts_plot():
   1550             data = self._maybe_convert_index(self.data)
   1551             self._make_ts_plot(data)

C:\Python34\lib\site-packages\pandas\tools\plotting.py in _is_ts_plot(self)
   1541     def _is_ts_plot(self):
   1542         # this is slightly deceptive
-> 1543         return not self.x_compat and self.use_index and self._use_dynamic_x()
   1544 
   1545     def _make_plot(self):

C:\Python34\lib\site-packages\pandas\tools\plotting.py in _use_dynamic_x(self)
   1537                 return False
   1538 
-> 1539         return (freq is not None) and self._is_dynamic_freq(freq)
   1540 
   1541     def _is_ts_plot(self):

C:\Python34\lib\site-packages\pandas\tools\plotting.py in _is_dynamic_freq(self, freq)
   1510             freq = get_base_alias(freq)
   1511         freq = get_period_alias(freq)
-> 1512         return freq is not None and self._no_base(freq)
   1513 
   1514     def _no_base(self, freq):

C:\Python34\lib\site-packages\pandas\tools\plotting.py in _no_base(self, freq)
   1518             and isinstance(self.data.index, DatetimeIndex)):
   1519             import pandas.tseries.frequencies as freqmod
-> 1520             base = freqmod.get_freq(freq)
   1521             x = self.data.index
   1522             if (base <= freqmod.FreqGroup.FR_DAY):

C:\Python34\lib\site-packages\pandas\tseries\frequencies.py in get_freq(freq)
     67 def get_freq(freq):
     68     if isinstance(freq, compat.string_types):
---> 69         base, mult = get_freq_code(freq)
     70         freq = base
     71     return freq

C:\Python34\lib\site-packages\pandas\tseries\frequencies.py in get_freq_code(freqstr)
    105 
    106     base, stride = _base_and_stride(freqstr)
--> 107     code = _period_str_to_code(base)
    108 
    109     return code, stride

C:\Python34\lib\site-packages\pandas\tseries\frequencies.py in _period_str_to_code(freqstr)
    612             alias = _period_alias_dict[freqstr]
    613         except KeyError:
--> 614             raise ValueError("Unknown freqstr: %s" % freqstr)
    615 
    616         return _period_code_map[alias]

ValueError: Unknown freqstr: C
Contributor

jreback commented May 23, 2014

post pd.show_versions() as well (e.g. which numpy are you on)

Contributor

jreback commented May 23, 2014

its converting it to a PeriodIndex which is not supported by that freq....

Contributor

seth-p commented May 23, 2014

pd.show_versions()

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

pandas: 0.14.0rc1-51-gccd593f
nose: None
Cython: 0.20.1
numpy: 1.8.1
scipy: 0.14.0
statsmodels: 0.5.0
IPython: 2.1.0
sphinx: None
patsy: 0.2.1
scikits.timeseries: None
dateutil: 2.2
pytz: 2014.3
bottleneck: 0.8.0
tables: 3.1.1
numexpr: 2.4
matplotlib: 1.3.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: 0.5.5
lxml: None
bs4: None
html5lib: None
bq: None
apiclient: None
rpy2: None
sqlalchemy: 0.9.4
pymysql: None
psycopg2: None

jreback added this to the 0.14.1 milestone May 23, 2014

seth-p changed the title from Series.plot() doesn't work with CustomBusinessDay frequency to BUG: Series.plot() doesn't work with CustomBusinessDay frequency Jun 26, 2014

Contributor

twiecki commented Jun 29, 2014

Running into the same issue.

@jreback jreback modified the milestone: 0.15.0, 0.14.1 Jul 1, 2014

Running into the same issue.

Contributor

ssanderson commented Sep 17, 2014

Ran into the same issue. Worked around it by doing series.asfreq('D').interpolate(how='time').plot(), which does a decent job visually, but is not the most elegant to write.

Contributor

ssanderson commented Sep 17, 2014

Passing x_compat=True also appears to be a decent workaround.

@jreback jreback modified the milestone: 0.16.0, Next Major Release Mar 6, 2015

Contributor

scari commented Feb 11, 2016

Ran into same problem and took a look a bit. I believe freqstr 'C' should be in _period_code_map. I'll send a PR after finish the test.

@scari scari added a commit to scari/pandas that referenced this issue Feb 12, 2016

@scari @scari scari + scari BUG: Series.plot() doesn't work with CustomBusinessDay frequency
Closes #7222
Missing freqstr 'C' in _period_code_map
83ca60f

@jreback jreback modified the milestone: 0.18.0, Next Major Release Feb 12, 2016

jreback closed this in 3e4c572 Feb 12, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment