Skip to content

Commit 0a00c47

Browse files
committed
Merge pull request #7026 from jreback/float_ni
BUG: error in Float64Index with contains and non-float (GH7025)
2 parents cafb835 + 3de6ceb commit 0a00c47

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

doc/source/release.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ Bug Fixes
456456
- Bug in ``iloc`` when setting / aligning (:issue:`6766`)
457457
- Bug causing UnicodeEncodeError when get_dummies called with unicode values and a prefix (:issue:`6885`)
458458
- Bug in timeseries-with-frequency plot cursor display (:issue:`5453`)
459+
- Bug surfaced in groupby.plot when using a ``Float64Index`` (:issue:`7025`)
459460

460461
pandas 0.13.1
461462
-------------

pandas/core/index.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,8 @@ def __contains__(self, other):
20472047
return len(other) <= 1 and _try_get_item(other) in self
20482048
except TypeError:
20492049
return False
2050+
except:
2051+
return False
20502052

20512053
def get_loc(self, key):
20522054
if np.isnan(key):

pandas/tests/test_groupby.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
import pandas as pd
3434
from numpy.testing import assert_equal
3535

36+
def _skip_if_mpl_not_installed():
37+
try:
38+
import matplotlib.pyplot as plt
39+
except ImportError:
40+
raise nose.SkipTest("matplotlib not installed")
3641

3742
def commonSetUp(self):
3843
self.dateRange = bdate_range('1/1/2005', periods=250)
@@ -3976,11 +3981,8 @@ def test_groupby_blacklist(self):
39763981
getattr(gb, bl)
39773982

39783983
def test_series_groupby_plotting_nominally_works(self):
3979-
try:
3980-
import matplotlib as mpl
3981-
mpl.use('Agg')
3982-
except ImportError:
3983-
raise nose.SkipTest("matplotlib not installed")
3984+
_skip_if_mpl_not_installed()
3985+
39843986
n = 10
39853987
weight = Series(np.random.normal(166, 20, size=n))
39863988
height = Series(np.random.normal(60, 10, size=n))
@@ -3991,14 +3993,26 @@ def test_series_groupby_plotting_nominally_works(self):
39913993
height.groupby(gender).hist()
39923994
tm.close()
39933995

3996+
def test_plotting_with_float_index_works(self):
3997+
_skip_if_mpl_not_installed()
3998+
3999+
# GH 7025
4000+
df = DataFrame({'def': [1,1,1,2,2,2,3,3,3],
4001+
'val': np.random.randn(9)},
4002+
index=[1.0,2.0,3.0,1.0,2.0,3.0,1.0,2.0,3.0])
4003+
4004+
df.groupby('def')['val'].plot()
4005+
tm.close()
4006+
df.groupby('def')['val'].apply(lambda x: x.plot())
4007+
tm.close()
4008+
39944009
@slow
39954010
def test_frame_groupby_plot_boxplot(self):
3996-
try:
3997-
import matplotlib.pyplot as plt
3998-
import matplotlib as mpl
3999-
mpl.use('Agg')
4000-
except ImportError:
4001-
raise nose.SkipTest("matplotlib not installed")
4011+
_skip_if_mpl_not_installed()
4012+
4013+
import matplotlib.pyplot as plt
4014+
import matplotlib as mpl
4015+
mpl.use('Agg')
40024016
tm.close()
40034017

40044018
n = 10
@@ -4029,12 +4043,10 @@ def test_frame_groupby_plot_boxplot(self):
40294043

40304044
@slow
40314045
def test_frame_groupby_hist(self):
4032-
try:
4033-
import matplotlib.pyplot as plt
4034-
import matplotlib as mpl
4035-
mpl.use('Agg')
4036-
except ImportError:
4037-
raise nose.SkipTest("matplotlib not installed")
4046+
_skip_if_mpl_not_installed()
4047+
import matplotlib.pyplot as plt
4048+
import matplotlib as mpl
4049+
mpl.use('Agg')
40384050
tm.close()
40394051

40404052
n = 10

0 commit comments

Comments
 (0)