Repository: pandas-dev/pandas

Issue:
GroupBy with Float Index not Plotting
I have the following problem: I have a dataset with a float index that I want to group and plot. If I'm using integer indices it works, with floats it doesn't. Here is the minimal example that once works and once not. I'm testing with the current master. Am I doing something wrong?

This code snippet fails:

```
import pandas as pd
import numpy as np
test = pd.DataFrame({'def': [1,1,1,2,2,2,3,3,3], 'val': np.random.randn(9)}, index=[1.0,2.0,3.0,1.0,2.0,3.0,1.0,2.0,3.0])
test.groupby('def')['val'].plot()
```

While this works:

```
# This Works
test = pd.DataFrame({'def': [1,1,1,2,2,2,3,3,3], 'val': np.random.randn(9)}, index= [1,2,3,1,2,3,1,2,3])
test.groupby('def')['val'].plot()
```

The error I get is:

```
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-83-e50f1a9b07c6> in <module>()
----> 1 test.groupby('def')['val'].plot()

/Library/Python/2.7/site-packages/pandas-0.13.1_758_g4a67608-py2.7-macosx-10.9-intel.egg/pandas/core/groupby.pyc in __getattr__(self, attr)
    452         if attr in self._internal_names_set:
    453             return object.__getattribute__(self, attr)
--> 454         if attr in self.obj:
    455             return self[attr]
    456 

/Library/Python/2.7/site-packages/pandas-0.13.1_758_g4a67608-py2.7-macosx-10.9-intel.egg/pandas/core/series.pyc in __contains__(self, key)
    379 
    380     def __contains__(self, key):
--> 381         return key in self.index
    382 
    383     # complex

/Library/Python/2.7/site-packages/pandas-0.13.1_758_g4a67608-py2.7-macosx-10.9-intel.egg/pandas/core/index.pyc in __contains__(self, other)
   2042         try:
   2043             # if other is a sequence this throws a ValueError
-> 2044             return np.isnan(other) and self._hasnans
   2045         except ValueError:
   2046             try:

NotImplementedError: Not implemented for this type
```



Discussion:
This is a bug,

as a work-around try this:

```
test.groupby('def')['val'].apply(lambda x: x.plot())
```

Thank you! This helps. 

Should I leave this issue open?


Resolving patch:
diff --git a/pandas/core/index.py b/pandas/core/index.py
--- a/pandas/core/index.py
+++ b/pandas/core/index.py
@@ -2047,6 +2047,8 @@ def __contains__(self, other):
                 return len(other) <= 1 and _try_get_item(other) in self
             except TypeError:
                 return False
+        except:
+            return False
 
     def get_loc(self, key):
         if np.isnan(key):


Test patch:
diff --git a/pandas/tests/test_groupby.py b/pandas/tests/test_groupby.py
--- a/pandas/tests/test_groupby.py
+++ b/pandas/tests/test_groupby.py
@@ -33,6 +33,11 @@
 import pandas as pd
 from numpy.testing import assert_equal
 
+def _skip_if_mpl_not_installed():
+    try:
+        import matplotlib.pyplot as plt
+    except ImportError:
+        raise nose.SkipTest("matplotlib not installed")
 
 def commonSetUp(self):
     self.dateRange = bdate_range('1/1/2005', periods=250)
@@ -3976,11 +3981,8 @@ def test_groupby_blacklist(self):
                     getattr(gb, bl)
 
     def test_series_groupby_plotting_nominally_works(self):
-        try:
-            import matplotlib as mpl
-            mpl.use('Agg')
-        except ImportError:
-            raise nose.SkipTest("matplotlib not installed")
+        _skip_if_mpl_not_installed()
+
         n = 10
         weight = Series(np.random.normal(166, 20, size=n))
         height = Series(np.random.normal(60, 10, size=n))
@@ -3991,14 +3993,26 @@ def test_series_groupby_plotting_nominally_works(self):
         height.groupby(gender).hist()
         tm.close()
 
+    def test_plotting_with_float_index_works(self):
+        _skip_if_mpl_not_installed()
+
+        # GH 7025
+        df = DataFrame({'def': [1,1,1,2,2,2,3,3,3],
+                        'val': np.random.randn(9)},
+                       index=[1.0,2.0,3.0,1.0,2.0,3.0,1.0,2.0,3.0])
+
+        df.groupby('def')['val'].plot()
+        tm.close()
+        df.groupby('def')['val'].apply(lambda x: x.plot())
+        tm.close()
+
     @slow
     def test_frame_groupby_plot_boxplot(self):
-        try:
-            import matplotlib.pyplot as plt
-            import matplotlib as mpl
-            mpl.use('Agg')
-        except ImportError:
-            raise nose.SkipTest("matplotlib not installed")
+        _skip_if_mpl_not_installed()
+
+        import matplotlib.pyplot as plt
+        import matplotlib as mpl
+        mpl.use('Agg')
         tm.close()
 
         n = 10
@@ -4029,12 +4043,10 @@ def test_frame_groupby_plot_boxplot(self):
 
     @slow
     def test_frame_groupby_hist(self):
-        try:
-            import matplotlib.pyplot as plt
-            import matplotlib as mpl
-            mpl.use('Agg')
-        except ImportError:
-            raise nose.SkipTest("matplotlib not installed")
+        _skip_if_mpl_not_installed()
+        import matplotlib.pyplot as plt
+        import matplotlib as mpl
+        mpl.use('Agg')
         tm.close()
 
         n = 10