Skip to content

BUG: Holiday(..) with both offset and observance raises #10226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Backwards incompatible API changes
Other API Changes
^^^^^^^^^^^^^^^^^

- ``Holiday`` now raises NotImplementedError if both offset and observance are used in constructor. (:issue:`102171`)

.. _whatsnew_0170.deprecations:

Deprecations
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/test_tseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import pandas.lib as lib
import pandas._period as period
import pandas.algos as algos
from pandas.tseries.holiday import Holiday, SA, next_monday
from pandas import DateOffset


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


class TestHolidayConflictingArguments(tm.TestCase):

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add the issue number as a comment here

# GH 10217

def test_both_offset_observance_raises(self):

with self.assertRaises(NotImplementedError) as cm:
h = Holiday("Cyber Monday", month=11, day=1,
offset=[DateOffset(weekday=SA(4))], observance=next_monday)

if __name__ == '__main__':
import nose
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
Expand Down
3 changes: 3 additions & 0 deletions pandas/tseries/holiday.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ class from pandas.tseries.offsets
>>> July3rd = Holiday('July 3rd', month=7, day=3,
days_of_week=(0, 1, 2, 3))
"""
if offset is not None and observance is not None:
raise NotImplementedError("Cannot use both offset and observance.")

self.name = name
self.year = year
self.month = month
Expand Down