From ba9055297b1e0fdcd19ab3bfa58e56b01eb1d267 Mon Sep 17 00:00:00 2001 From: Garrett Drapala Date: Sat, 29 Mar 2014 15:34:11 -0400 Subject: [PATCH] BUG: prevent ndarray indexing with float (+ test) --- pandas/compat/scipy.py | 2 +- pandas/tests/test_scipy.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 pandas/tests/test_scipy.py diff --git a/pandas/compat/scipy.py b/pandas/compat/scipy.py index 81601ffe25609..9acfae48160a7 100644 --- a/pandas/compat/scipy.py +++ b/pandas/compat/scipy.py @@ -65,7 +65,7 @@ def scoreatpercentile(a, per, limit=(), interpolation_method='fraction'): idx = per / 100. * (values.shape[0] - 1) if idx % 1 == 0: - score = values[idx] + score = values[int(idx)] else: if interpolation_method == 'fraction': score = _interpolate(values[int(idx)], values[int(idx) + 1], diff --git a/pandas/tests/test_scipy.py b/pandas/tests/test_scipy.py new file mode 100644 index 0000000000000..290c9c66d7979 --- /dev/null +++ b/pandas/tests/test_scipy.py @@ -0,0 +1,17 @@ +import numpy as np +import pandas as pd +from pandas.util.testing import assert_series_equal +import warnings + +def test_describe_with_warnings_raised(): + with warnings.catch_warnings(): + # escalate warnings + warnings.simplefilter("error") + df = pd.DataFrame({"A": [1, 2, 3], "B": [1.2, 4.2, 5.2]}) + act = df.groupby('A')['B'].describe().unstack(0) + exp = pd.Series( + [1.0, 1.2, np.NaN, 1.2, 1.2, 1.2, 1.2, 1.2], + ['count', 'mean', 'std', 'min', '25%', '50%', '75%', 'max'], + ) + assert_series_equal(act[1], exp) +