Skip to content

Commit 0db4304

Browse files
tom-birdjreback
authored andcommitted
BUG: Empty lists shouldn't be counted as DateOffsets.
closes pandas-dev#13844 closes pandas-dev#13889
1 parent e31f981 commit 0db4304

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

doc/source/whatsnew/v0.19.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,7 @@ Bug Fixes
11331133
- Regression in ``Series.quantile`` with nans (also shows up in ``.median()`` and ``.describe()`` ); furthermore now names the ``Series`` with the quantile (:issue:`13098`, :issue:`13146`)
11341134

11351135
- Bug in ``SeriesGroupBy.transform`` with datetime values and missing groups (:issue:`13191`)
1136+
- Bug where empty ``Series`` were incorrectly coerced in datetime-like numeric operations (:issue:`13844`)
11361137

11371138
- Bug in ``Series.str.extractall()`` with ``str`` index raises ``ValueError`` (:issue:`13156`)
11381139
- Bug in ``Series.str.extractall()`` with single group and quantifier (:issue:`13382`)

pandas/core/ops.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,9 @@ def _is_offset(self, arr_or_obj):
586586
""" check if obj or all elements of list-like is DateOffset """
587587
if isinstance(arr_or_obj, pd.DateOffset):
588588
return True
589-
elif is_list_like(arr_or_obj):
589+
elif is_list_like(arr_or_obj) and len(arr_or_obj):
590590
return all(isinstance(x, pd.DateOffset) for x in arr_or_obj)
591-
else:
592-
return False
591+
return False
593592

594593

595594
def _align_method_SERIES(left, right, align_asobject=False):

pandas/tests/series/test_timeseries.py

+9
Original file line numberDiff line numberDiff line change
@@ -552,3 +552,12 @@ def test_timeseries_coercion(self):
552552
self.assertTrue(ser.is_time_series)
553553
self.assertTrue(ser.index.is_all_dates)
554554
self.assertIsInstance(ser.index, DatetimeIndex)
555+
556+
def test_empty_series_ops(self):
557+
# see issue #13844
558+
a = Series(dtype='M8[ns]')
559+
b = Series(dtype='m8[ns]')
560+
assert_series_equal(a, a + b)
561+
assert_series_equal(a, a - b)
562+
assert_series_equal(a, b + a)
563+
self.assertRaises(TypeError, lambda x, y: x - y, b, a)

0 commit comments

Comments
 (0)