Skip to content

Commit 04b9349

Browse files
jessegrabowskiricardoV94
authored andcommitted
Add checks against time coordinate if it was set by user before calling build_statespace_graph
1 parent 61bf56c commit 04b9349

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pymc_experimental/statespace/utils/data_tools.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,18 @@ def add_data_to_active_model(values, index):
112112
if OBS_STATE_DIM in pymc_mod.coords:
113113
data_dims = [TIME_DIM, OBS_STATE_DIM]
114114

115-
pymc_mod.add_coord(TIME_DIM, index)
115+
if TIME_DIM not in pymc_mod.coords:
116+
pymc_mod.add_coord(TIME_DIM, index)
117+
else:
118+
found_time = pymc_mod.coords[TIME_DIM]
119+
if found_time is None:
120+
pymc_mod.coords.update({TIME_DIM: index})
121+
elif not np.array_equal(found_time, index):
122+
raise ValueError(
123+
"Provided data has a different time index than the model. Please ensure that the time values "
124+
"set on coords matches that of the exogenous data."
125+
)
126+
116127
data = pm.Data("data", values, dims=data_dims)
117128

118129
return data

0 commit comments

Comments
 (0)