diff --git a/doc/source/release.rst b/doc/source/release.rst index a0a96ebbd5c70..cfc23267f8ece 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -456,6 +456,7 @@ Bug Fixes - Bug in ``iloc`` when setting / aligning (:issue:`6766`) - Bug causing UnicodeEncodeError when get_dummies called with unicode values and a prefix (:issue:`6885`) - Bug in timeseries-with-frequency plot cursor display (:issue:`5453`) +- Bug surfaced in groupby.plot when using a ``Float64Index`` (:issue:`7025`) pandas 0.13.1 ------------- diff --git a/pandas/core/index.py b/pandas/core/index.py index ecef70d7aa43b..96ecb66e86c67 100644 --- 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): diff --git a/pandas/tests/test_groupby.py b/pandas/tests/test_groupby.py index d938cc28c2588..1b70ae0309b10 100644 --- 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