From d87273d59addda91bb4ae232f078341b30443b36 Mon Sep 17 00:00:00 2001 From: Ajay Saxena Date: Sun, 4 Dec 2016 19:19:22 -0500 Subject: [PATCH 1/9] added timedelta as valid type for conversion to integer --- pandas/core/missing.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/missing.py b/pandas/core/missing.py index b847415f274db..d98d6f375c104 100644 --- a/pandas/core/missing.py +++ b/pandas/core/missing.py @@ -187,7 +187,8 @@ def _interp_limit(invalid, fw_limit, bw_limit): if method in ('values', 'index'): inds = np.asarray(xvalues) # hack for DatetimeIndex, #1646 - if issubclass(inds.dtype.type, np.datetime64): + if (issubclass(inds.dtype.type, np.datetime64) or + issubclass(inds.dtype.type, np.timedelta64)): inds = inds.view(np.int64) if inds.dtype == np.object_: inds = lib.maybe_convert_objects(inds) From 822f55e4be4a9e0b8a0802579fcbe6dce7207062 Mon Sep 17 00:00:00 2001 From: Ajay Saxena Date: Mon, 5 Dec 2016 23:35:00 -0500 Subject: [PATCH 2/9] added test case for change --- pandas/tests/series/test_missing.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index 4e6c58df54dfd..653742774a9c3 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -891,6 +891,15 @@ def test_spline_error(self): with tm.assertRaises(ValueError): s.interpolate(method='spline', order=0) + def test_interp_timedelta64(self): + # GH 14799 + tm._skip_if_no_scipy() + df = Series([1, np.nan, 3], index=pd.to_datetime([1, 2, 3], unit="d")) + result = df.interpolate(method='time') + expected = Series([1., 2., 3.], + index=pd.to_datetime([1, 2, 3], unit="d")) + assert_series_equal(result, expected) + if __name__ == '__main__': import nose From 81dab58e01ded74d391c4944eda93aa388d08eb0 Mon Sep 17 00:00:00 2001 From: Ajay Saxena Date: Tue, 6 Dec 2016 00:18:15 -0500 Subject: [PATCH 3/9] updated test with correct issue number and timedelta as index --- pandas/tests/series/test_missing.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index 653742774a9c3..11d4ded590d89 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -892,12 +892,13 @@ def test_spline_error(self): s.interpolate(method='spline', order=0) def test_interp_timedelta64(self): - # GH 14799 + # GH 6424 tm._skip_if_no_scipy() - df = Series([1, np.nan, 3], index=pd.to_datetime([1, 2, 3], unit="d")) + df = Series([1, np.nan, 3], + index=pd.to_timedelta([1, 2, 3])) result = df.interpolate(method='time') expected = Series([1., 2., 3.], - index=pd.to_datetime([1, 2, 3], unit="d")) + index=pd.to_timedelta([1, 2, 3])) assert_series_equal(result, expected) From 18b756c5f6e4606f1d7f635b6a2751af0e548e85 Mon Sep 17 00:00:00 2001 From: Ajay Saxena Date: Tue, 6 Dec 2016 20:26:35 -0500 Subject: [PATCH 4/9] checking if index is of time type using needs_i8_conversion --- pandas/core/missing.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/missing.py b/pandas/core/missing.py index d98d6f375c104..bfbc431c6b690 100644 --- a/pandas/core/missing.py +++ b/pandas/core/missing.py @@ -12,7 +12,8 @@ is_float_dtype, is_datetime64_dtype, is_integer_dtype, _ensure_float64, is_scalar, - _DATELIKE_DTYPES) + _DATELIKE_DTYPES, + needs_i8_conversion) from pandas.types.missing import isnull @@ -187,8 +188,7 @@ def _interp_limit(invalid, fw_limit, bw_limit): if method in ('values', 'index'): inds = np.asarray(xvalues) # hack for DatetimeIndex, #1646 - if (issubclass(inds.dtype.type, np.datetime64) or - issubclass(inds.dtype.type, np.timedelta64)): + if (needs_i8_conversion(inds.dtype.type)): inds = inds.view(np.int64) if inds.dtype == np.object_: inds = lib.maybe_convert_objects(inds) From 95722ff2a52303d7f6a2b82b5e1428eac3fd72bd Mon Sep 17 00:00:00 2001 From: Ajay Saxena Date: Wed, 7 Dec 2016 18:04:09 -0500 Subject: [PATCH 5/9] code review changes --- pandas/core/missing.py | 2 +- pandas/tests/series/test_missing.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pandas/core/missing.py b/pandas/core/missing.py index bfbc431c6b690..f1191ff1c7009 100644 --- a/pandas/core/missing.py +++ b/pandas/core/missing.py @@ -188,7 +188,7 @@ def _interp_limit(invalid, fw_limit, bw_limit): if method in ('values', 'index'): inds = np.asarray(xvalues) # hack for DatetimeIndex, #1646 - if (needs_i8_conversion(inds.dtype.type)): + if needs_i8_conversion(inds.dtype.type): inds = inds.view(np.int64) if inds.dtype == np.object_: inds = lib.maybe_convert_objects(inds) diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index 11d4ded590d89..5666a07cad4b8 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -893,7 +893,6 @@ def test_spline_error(self): def test_interp_timedelta64(self): # GH 6424 - tm._skip_if_no_scipy() df = Series([1, np.nan, 3], index=pd.to_timedelta([1, 2, 3])) result = df.interpolate(method='time') @@ -901,6 +900,14 @@ def test_interp_timedelta64(self): index=pd.to_timedelta([1, 2, 3])) assert_series_equal(result, expected) + # test for non uniform spacing + df = Series([1, np.nan, 3], + index=pd.to_timedelta([1, 2, 4])) + result = df.interpolate(method='time') + expected = Series([1., 1.666667, 3.], + index=pd.to_timedelta([1, 2, 4])) + assert_series_equal(result, expected) + if __name__ == '__main__': import nose From 579c4bb5d060e7fb5286b766e3a477bf34a6b035 Mon Sep 17 00:00:00 2001 From: Ajay Saxena Date: Fri, 9 Dec 2016 12:31:08 -0500 Subject: [PATCH 6/9] rebase changes --- doc/source/whatsnew/v0.20.0.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index d89103309e990..fe405a0ec4076 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -59,6 +59,7 @@ Other enhancements - ``Series`` provides a ``to_excel`` method to output Excel files (:issue:`8825`) - The ``usecols`` argument in ``pd.read_csv`` now accepts a callable function as a value (:issue:`14154`) - ``pd.DataFrame.plot`` now prints a title above each subplot if ``suplots=True`` and ``title`` is a list of strings (:issue:`14753`) +- The ``pd.Series.interpolate`` now supports timedelta as index type(:issue:`6424`) .. _whatsnew_0200.api_breaking: From b72ab91c7aea945eed14f91e5291d2dc3cb169dc Mon Sep 17 00:00:00 2001 From: Ajay Saxena Date: Fri, 9 Dec 2016 16:05:54 -0500 Subject: [PATCH 7/9] whatsnew changes --- doc/source/whatsnew/v0.20.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index fe405a0ec4076..65ff8ab05190a 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -59,7 +59,7 @@ Other enhancements - ``Series`` provides a ``to_excel`` method to output Excel files (:issue:`8825`) - The ``usecols`` argument in ``pd.read_csv`` now accepts a callable function as a value (:issue:`14154`) - ``pd.DataFrame.plot`` now prints a title above each subplot if ``suplots=True`` and ``title`` is a list of strings (:issue:`14753`) -- The ``pd.Series.interpolate`` now supports timedelta as index type(:issue:`6424`) +- The ``pd.Series.interpolate`` now supports timedelta as index type with method=`time` (:issue:`6424`) .. _whatsnew_0200.api_breaking: From fff59f5589b0ca47a755ab071120288819b4e167 Mon Sep 17 00:00:00 2001 From: Ajay Saxena Date: Fri, 9 Dec 2016 16:56:29 -0500 Subject: [PATCH 8/9] whatsnew message typos --- doc/source/whatsnew/v0.20.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index 65ff8ab05190a..45f8f62147d9c 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -59,7 +59,7 @@ Other enhancements - ``Series`` provides a ``to_excel`` method to output Excel files (:issue:`8825`) - The ``usecols`` argument in ``pd.read_csv`` now accepts a callable function as a value (:issue:`14154`) - ``pd.DataFrame.plot`` now prints a title above each subplot if ``suplots=True`` and ``title`` is a list of strings (:issue:`14753`) -- The ``pd.Series.interpolate`` now supports timedelta as index type with method=`time` (:issue:`6424`) +- ``pd.Series.interpolate`` now supports timedelta as an index type with method=``time`` (:issue:`6424`) .. _whatsnew_0200.api_breaking: From 562a793265174780f10bcfe55ae1509eacc70704 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sat, 10 Dec 2016 12:17:43 +0100 Subject: [PATCH 9/9] edit whatsnew line --- doc/source/whatsnew/v0.20.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index 45f8f62147d9c..f534c67273560 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -59,7 +59,7 @@ Other enhancements - ``Series`` provides a ``to_excel`` method to output Excel files (:issue:`8825`) - The ``usecols`` argument in ``pd.read_csv`` now accepts a callable function as a value (:issue:`14154`) - ``pd.DataFrame.plot`` now prints a title above each subplot if ``suplots=True`` and ``title`` is a list of strings (:issue:`14753`) -- ``pd.Series.interpolate`` now supports timedelta as an index type with method=``time`` (:issue:`6424`) +- ``pd.Series.interpolate`` now supports timedelta as an index type with ``method='time'`` (:issue:`6424`) .. _whatsnew_0200.api_breaking: