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`) 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..3fa1fc8e02a2e 100644 --- a/pandas/tests/series/test_timeseries.py +++ b/pandas/tests/series/test_timeseries.py @@ -525,3 +525,12 @@ 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_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)