From 25f4822557998bc6567535bea4dc8b0263258a56 Mon Sep 17 00:00:00 2001 From: TomAugspurger Date: Wed, 10 Sep 2014 10:16:41 -0500 Subject: [PATCH] BUG: interpolate with no nans and limit --- doc/source/v0.15.0.txt | 5 +++++ pandas/core/common.py | 2 ++ pandas/tests/test_generic.py | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/doc/source/v0.15.0.txt b/doc/source/v0.15.0.txt index 496230bd5f3a1..029a38507275d 100644 --- a/doc/source/v0.15.0.txt +++ b/doc/source/v0.15.0.txt @@ -756,3 +756,8 @@ Bug Fixes - Bug with kde plot and NaNs (:issue:`8182`) - Bug in ``GroupBy.count`` with float32 data type were nan values were not excluded (:issue:`8169`). - Bug with stacked barplots and NaNs (:issue:`8175`). + + + +- Bug in interpolation methods with the ``limit`` keyword when no values +needed interpolating (:issue:`7173`). diff --git a/pandas/core/common.py b/pandas/core/common.py index e3a0cf14cfbc1..c0b6d9dbe15b5 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -1534,6 +1534,8 @@ def interpolate_1d(xvalues, yvalues, method='linear', limit=None, def _interp_limit(invalid, limit): """mask off values that won't be filled since they exceed the limit""" all_nans = np.where(invalid)[0] + if all_nans.size == 0: # no nans anyway + return [] violate = [invalid[x:x + limit + 1] for x in all_nans] violate = np.array([x.all() & (x.size > limit) for x in violate]) return all_nans[violate] + limit diff --git a/pandas/tests/test_generic.py b/pandas/tests/test_generic.py index b1877ddb81ee1..2c5f100843445 100644 --- a/pandas/tests/test_generic.py +++ b/pandas/tests/test_generic.py @@ -656,6 +656,13 @@ def test_interp_datetime64(self): expected = Series([1., 1., 3.], index=date_range('1/1/2000', periods=3)) assert_series_equal(result, expected) + def test_interp_limit_no_nans(self): + # GH 7173 + s = pd.Series([1., 2., 3.]) + result = s.interpolate(limit=1) + expected = s + assert_series_equal(result, expected) + def test_describe(self): _ = self.series.describe() _ = self.ts.describe()