Skip to content

Commit d513986

Browse files
bwillersjreback
authored andcommitted
BUG: Holiday(..) with both offset and observance raises NotImplementedError #10217
GH10217
1 parent 5852e72 commit d513986

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

doc/source/whatsnew/v0.17.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Backwards incompatible API changes
3838
Other API Changes
3939
^^^^^^^^^^^^^^^^^
4040

41+
- ``Holiday`` now raises ``NotImplementedError`` if both ``offset`` and ``observance`` are used in constructor. (:issue:`102171`)
42+
4143
.. _whatsnew_0170.deprecations:
4244

4345
Deprecations

pandas/tests/test_tseries.py

+13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import pandas.lib as lib
1010
import pandas._period as period
1111
import pandas.algos as algos
12+
from pandas.tseries.holiday import Holiday, SA, next_monday
13+
from pandas import DateOffset
1214

1315

1416
class TestTseriesUtil(tm.TestCase):
@@ -737,6 +739,17 @@ def test_get_period_field_raises_on_out_of_range(self):
737739
def test_get_period_field_array_raises_on_out_of_range(self):
738740
self.assertRaises(ValueError, period.get_period_field_arr, -1, np.empty(1), 0)
739741

742+
743+
class TestHolidayConflictingArguments(tm.TestCase):
744+
745+
# GH 10217
746+
747+
def test_both_offset_observance_raises(self):
748+
749+
with self.assertRaises(NotImplementedError) as cm:
750+
h = Holiday("Cyber Monday", month=11, day=1,
751+
offset=[DateOffset(weekday=SA(4))], observance=next_monday)
752+
740753
if __name__ == '__main__':
741754
import nose
742755
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],

pandas/tseries/holiday.py

+3
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ class from pandas.tseries.offsets
148148
>>> July3rd = Holiday('July 3rd', month=7, day=3,
149149
days_of_week=(0, 1, 2, 3))
150150
"""
151+
if offset is not None and observance is not None:
152+
raise NotImplementedError("Cannot use both offset and observance.")
153+
151154
self.name = name
152155
self.year = year
153156
self.month = month

0 commit comments

Comments
 (0)