Skip to content

Commit 9166e29

Browse files
committed
Adding a test ton ensure an exception is raised when when type(data.index) != type(time_range.index)
1 parent f82d7d3 commit 9166e29

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

causalpy/tests/test_integration_pymc_examples.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,25 @@ def test_cp_covid():
450450
exc_info.value
451451
)
452452

453+
# Assert that we correctfully raise a BadIndexException if
454+
# - time_range is not None
455+
# - time_range is not of type Iterable[pd.TimeStamp]
456+
# - DataIndex is of type pd.DatetimeIndex
457+
with pytest.raises(cp.custom_exceptions.DataException) as exc_info:
458+
cp.ChangePointDetection(
459+
df,
460+
time_range=[0, 0],
461+
formula="standardize(deaths) ~ 0 + t + C(month) + standardize(temp)", # noqa E501
462+
model=cp.pymc_models.LinearChangePointDetection(
463+
cp_effect_type=["impulse", "level", "trend"],
464+
sample_kwargs=sample_kwargs,
465+
),
466+
)
467+
assert (
468+
"If data.index is DatetimeIndex, time_range must be of type Iterable[pd.Timestamp]."
469+
in str(exc_info.value)
470+
)
471+
453472
result = cp.ChangePointDetection(
454473
df,
455474
time_range=time_range,

0 commit comments

Comments
 (0)