From 98c1fe000f6f04b0315a3687f8d4551a3ecacb92 Mon Sep 17 00:00:00 2001 From: Sam Ehrenstein Date: Mon, 6 Jan 2025 21:29:16 -0500 Subject: [PATCH 1/2] warn when CustomBusiness day is passed a non-null calendar param value that is not an np.busdaycalendar --- pandas/_libs/tslibs/offsets.pyx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 7569f8e8864a0..6f1b4983f97c0 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -4423,6 +4423,8 @@ cdef class CustomBusinessDay(BusinessDay): offset=timedelta(0), ): BusinessDay.__init__(self, n, normalize, offset) + if (calendar is not None) and not isinstance(calendar, np.busdaycalendar): + warnings.warn("Warning: `calendar` is expected to be either an instance of `np.busdaycalendar` or `None`.") self._init_custom(weekmask, holidays, calendar) cpdef __setstate__(self, state): From 335aff221de75eb63815be8cdf9bed2436402fe1 Mon Sep 17 00:00:00 2001 From: Sam Ehrenstein Date: Mon, 6 Jan 2025 21:58:33 -0500 Subject: [PATCH 2/2] switch to error instead of warning --- pandas/_libs/tslibs/offsets.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 6f1b4983f97c0..132272b534e07 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -4424,7 +4424,7 @@ cdef class CustomBusinessDay(BusinessDay): ): BusinessDay.__init__(self, n, normalize, offset) if (calendar is not None) and not isinstance(calendar, np.busdaycalendar): - warnings.warn("Warning: `calendar` is expected to be either an instance of `np.busdaycalendar` or `None`.") + raise TypeError("`calendar` is expected to be either an instance of `np.busdaycalendar` or `None`.") self._init_custom(weekmask, holidays, calendar) cpdef __setstate__(self, state):