Skip to content

BUG: error in Float64Index with contains and non-float (GH7025) #7026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------
Expand Down
2 changes: 2 additions & 0 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
46 changes: 29 additions & 17 deletions pandas/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down