From 179f8ce07a3fa16f35674fc57bae9a0e5c3d6097 Mon Sep 17 00:00:00 2001 From: Tom Bird Date: Wed, 3 Aug 2016 18:48:45 +0100 Subject: [PATCH 1/3] BUG: Empty lists shouldn't be counted as DateOffsets. See #13844 BUG: Empty lists shouldn't be counted as DateOffsets. See #13844 BUG: Empty lists shouldn't be counted as DateOffsets. See #13844 --- pandas/core/ops.py | 5 ++--- pandas/tests/series/test_timeseries.py | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pandas/core/ops.py b/pandas/core/ops.py index 44e3be32c23df..81741b06dcea2 100644 --- a/pandas/core/ops.py +++ b/pandas/core/ops.py @@ -597,10 +597,9 @@ def _is_offset(self, arr_or_obj): """ check if obj or all elements of list-like is DateOffset """ if isinstance(arr_or_obj, pd.DateOffset): return True - elif is_list_like(arr_or_obj): + elif is_list_like(arr_or_obj) and len(arr_or_obj): return all(isinstance(x, pd.DateOffset) for x in arr_or_obj) - else: - return False + return False def _arith_method_SERIES(op, name, str_rep, fill_zeros=None, default_axis=None, diff --git a/pandas/tests/series/test_timeseries.py b/pandas/tests/series/test_timeseries.py index 19acf54c7a3cb..ce5334ee3fb0d 100644 --- a/pandas/tests/series/test_timeseries.py +++ b/pandas/tests/series/test_timeseries.py @@ -525,3 +525,11 @@ def test_timeseries_coercion(self): self.assertTrue(ser.is_time_series) self.assertTrue(ser.index.is_all_dates) self.assertIsInstance(ser.index, DatetimeIndex) + + def test_empty_series_addition(self): + # see issue #13844 + a = Series(dtype='M8[ns]') + b = Series(dtype='m8[ns]') + assert_series_equal(a, a + b) + assert_series_equal(a, a - b) + assert_series_equal(a, b + a) From cb26d2555b231342eb7ce23fabef2b34e4bfb980 Mon Sep 17 00:00:00 2001 From: Tom Bird Date: Sun, 7 Aug 2016 11:15:12 +0100 Subject: [PATCH 2/3] BUG: Empty lists shouldn't be counted as DateOffsets. See #13844 --- pandas/tests/series/test_timeseries.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/series/test_timeseries.py b/pandas/tests/series/test_timeseries.py index ce5334ee3fb0d..3fa1fc8e02a2e 100644 --- a/pandas/tests/series/test_timeseries.py +++ b/pandas/tests/series/test_timeseries.py @@ -526,10 +526,11 @@ def test_timeseries_coercion(self): self.assertTrue(ser.index.is_all_dates) self.assertIsInstance(ser.index, DatetimeIndex) - def test_empty_series_addition(self): + def test_empty_series_ops(self): # see issue #13844 a = Series(dtype='M8[ns]') b = Series(dtype='m8[ns]') assert_series_equal(a, a + b) assert_series_equal(a, a - b) assert_series_equal(a, b + a) + self.assertRaises(TypeError, lambda x, y: x - y, b, a) From c85b5b2c4ebe0e3f1f4c304754e7332c6ab0df4d Mon Sep 17 00:00:00 2001 From: Tom Bird Date: Sun, 21 Aug 2016 11:43:29 +0100 Subject: [PATCH 3/3] Empty lists shouldn't be counted as DateOffsets. See #13844 --- doc/source/whatsnew/v0.19.0.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.19.0.txt b/doc/source/whatsnew/v0.19.0.txt index 8b8ab505c9d44..3d6be758ba136 100644 --- a/doc/source/whatsnew/v0.19.0.txt +++ b/doc/source/whatsnew/v0.19.0.txt @@ -865,3 +865,4 @@ Bug Fixes - Bug in ``.to_excel()`` when DataFrame contains a MultiIndex which contains a label with a NaN value (:issue:`13511`) - Bug in ``pd.read_csv`` in Python 2.x with non-UTF8 encoded, multi-character separated data (:issue:`3404`) - Bug in ``Index`` raises ``KeyError`` displaying incorrect column when column is not in the df and columns contains duplicate values (:issue:`13822`) +- Bug where empty ``Series`` were being regarded as ``DateOffsets`` when used in a ``TimeOp``, even if they had a ``dtype`` (:issue:`13844`)