Repository: pandas-dev/pandas

Issue:
Plotting series with different frequency yields "ValueError: Incompatible frequency conversion"
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
```



Discussion:
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')


Resolving patch:
diff --git a/pandas/tseries/frequencies.py b/pandas/tseries/frequencies.py
--- a/pandas/tseries/frequencies.py
+++ b/pandas/tseries/frequencies.py
@@ -929,25 +929,31 @@ def is_subperiod(source, target):
         if _is_quarterly(source):
             return _quarter_months_conform(_get_rule_month(source),
                                            _get_rule_month(target))
-        return source in ['D', 'C', 'B', 'M', 'H', 'T', 'S']
+        return source in ['D', 'C', 'B', 'M', 'H', 'T', 'S', 'L', 'U', 'N']
     elif _is_quarterly(target):
-        return source in ['D', 'C', 'B', 'M', 'H', 'T', 'S']
+        return source in ['D', 'C', 'B', 'M', 'H', 'T', 'S', 'L', 'U', 'N']
     elif target == 'M':
-        return source in ['D', 'C', 'B', 'H', 'T', 'S']
+        return source in ['D', 'C', 'B', 'H', 'T', 'S', 'L', 'U', 'N']
     elif _is_weekly(target):
-        return source in [target, 'D', 'C', 'B', 'H', 'T', 'S']
+        return source in [target, 'D', 'C', 'B', 'H', 'T', 'S', 'L', 'U', 'N']
     elif target == 'B':
-        return source in ['B', 'H', 'T', 'S']
+        return source in ['B', 'H', 'T', 'S', 'L', 'U', 'N']
     elif target == 'C':
-        return source in ['C', 'H', 'T', 'S']
+        return source in ['C', 'H', 'T', 'S', 'L', 'U', 'N']
     elif target == 'D':
-        return source in ['D', 'H', 'T', 'S']
+        return source in ['D', 'H', 'T', 'S', 'L', 'U', 'N']
     elif target == 'H':
-        return source in ['H', 'T', 'S']
+        return source in ['H', 'T', 'S', 'L', 'U', 'N']
     elif target == 'T':
-        return source in ['T', 'S']
+        return source in ['T', 'S', 'L', 'U', 'N']
     elif target == 'S':
-        return source in ['S']
+        return source in ['S', 'L', 'U', 'N']
+    elif target == 'L':
+        return source in ['L', 'U', 'N']
+    elif target == 'U':
+        return source in ['U', 'N']
+    elif target == 'N':
+        return source in ['N']
 
 
 def is_superperiod(source, target):
@@ -982,25 +988,31 @@ def is_superperiod(source, target):
             smonth = _get_rule_month(source)
             tmonth = _get_rule_month(target)
             return _quarter_months_conform(smonth, tmonth)
-        return target in ['D', 'C', 'B', 'M', 'H', 'T', 'S']
+        return target in ['D', 'C', 'B', 'M', 'H', 'T', 'S', 'L', 'U', 'N']
     elif _is_quarterly(source):
-        return target in ['D', 'C', 'B', 'M', 'H', 'T', 'S']
+        return target in ['D', 'C', 'B', 'M', 'H', 'T', 'S', 'L', 'U', 'N']
     elif source == 'M':
-        return target in ['D', 'C', 'B', 'H', 'T', 'S']
+        return target in ['D', 'C', 'B', 'H', 'T', 'S', 'L', 'U', 'N']
     elif _is_weekly(source):
-        return target in [source, 'D', 'C', 'B', 'H', 'T', 'S']
+        return target in [source, 'D', 'C', 'B', 'H', 'T', 'S', 'L', 'U', 'N']
     elif source == 'B':
-        return target in ['D', 'C', 'B', 'H', 'T', 'S']
+        return target in ['D', 'C', 'B', 'H', 'T', 'S', 'L', 'U', 'N']
     elif source == 'C':
-        return target in ['D', 'C', 'B', 'H', 'T', 'S']
+        return target in ['D', 'C', 'B', 'H', 'T', 'S', 'L', 'U', 'N']
     elif source == 'D':
-        return target in ['D', 'C', 'B', 'H', 'T', 'S']
+        return target in ['D', 'C', 'B', 'H', 'T', 'S', 'L', 'U', 'N']
     elif source == 'H':
-        return target in ['H', 'T', 'S']
+        return target in ['H', 'T', 'S', 'L', 'U', 'N']
     elif source == 'T':
-        return target in ['T', 'S']
+        return target in ['T', 'S', 'L', 'U', 'N']
     elif source == 'S':
-        return target in ['S']
+        return target in ['S', 'L', 'U', 'N']
+    elif source == 'L':
+        return target in ['L', 'U', 'N']
+    elif source == 'U':
+        return target in ['U', 'N']
+    elif source == 'N':
+        return target in ['N']
 
 
 def _get_rule_month(source, default='DEC'):


Test patch:
diff --git a/pandas/tseries/tests/test_frequencies.py b/pandas/tseries/tests/test_frequencies.py
--- a/pandas/tseries/tests/test_frequencies.py
+++ b/pandas/tseries/tests/test_frequencies.py
@@ -342,6 +342,16 @@ def test_is_superperiod_subperiod():
     assert(fmod.is_superperiod(offsets.Hour(), offsets.Minute()))
     assert(fmod.is_subperiod(offsets.Minute(), offsets.Hour()))
 
+    assert(fmod.is_superperiod(offsets.Second(), offsets.Milli()))
+    assert(fmod.is_subperiod(offsets.Milli(), offsets.Second()))
+
+    assert(fmod.is_superperiod(offsets.Milli(), offsets.Micro()))
+    assert(fmod.is_subperiod(offsets.Micro(), offsets.Milli()))
+
+    assert(fmod.is_superperiod(offsets.Micro(), offsets.Nano()))
+    assert(fmod.is_subperiod(offsets.Nano(), offsets.Micro()))
+
+
 if __name__ == '__main__':
     import nose
     nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
diff --git a/pandas/tseries/tests/test_plotting.py b/pandas/tseries/tests/test_plotting.py
--- a/pandas/tseries/tests/test_plotting.py
+++ b/pandas/tseries/tests/test_plotting.py
@@ -707,6 +707,28 @@ def test_from_weekly_resampling(self):
         for l in ax.get_lines():
             self.assertTrue(PeriodIndex(data=l.get_xdata()).freq.startswith('W'))
 
+    @slow
+    def test_mixed_freq_second_millisecond(self):
+        # GH 7772, GH 7760
+        idxh = date_range('2014-07-01 09:00', freq='S', periods=50)
+        idxl = date_range('2014-07-01 09:00', freq='100L', periods=500)
+        high = Series(np.random.randn(len(idxh)), idxh)
+        low = Series(np.random.randn(len(idxl)), idxl)
+        # high to low
+        high.plot()
+        ax = low.plot()
+        self.assertEqual(len(ax.get_lines()), 2)
+        for l in ax.get_lines():
+            self.assertEqual(PeriodIndex(data=l.get_xdata()).freq, 'L')
+        tm.close()
+
+        # low to high
+        low.plot()
+        ax = high.plot()
+        self.assertEqual(len(ax.get_lines()), 2)
+        for l in ax.get_lines():
+            self.assertEqual(PeriodIndex(data=l.get_xdata()).freq, 'L')
+
     @slow
     def test_irreg_dtypes(self):
         # date