Skip to content

Check on Index of data too strict in statespace #384

@AlexAndorra

Description

@AlexAndorra

As discussed with @jessegrabowski , the statespace module has a check on indices of passed observed data that seems to strict: if you pass an integer Index, it will not accept it because it's technically not a RangeIndex:

a = pd.DataFrame(
    index=np.arange(8), columns=["A", "B", "C", "D"], data=np.arange(32).reshape(8, 4)
)

mod = st.LevelTrendComponent(order=2, innovations_order=[0, 1])
ss_mod = mod.build(name="a")

initial_trend_dims, sigma_trend_dims, P0_dims = (
    ss_mod.param_dims.values()
)
coords = ss_mod.coords

with pm.Model(coords=coords) as model_1:
    P0_diag = pm.Gamma("P0_diag", alpha=5, beta=5)
    P0 = pm.Deterministic("P0", pyt.eye(ss_mod.k_states) * P0_diag, dims=P0_dims)

    initial_trend = pm.Normal("initial_trend", dims=initial_trend_dims)
    sigma_trend = pm.Gamma("sigma_trend", alpha=2, beta=50, dims=sigma_trend_dims)

    ss_mod.build_statespace_graph(
        a["A"],
        mode="JAX",
    )
IndexError: Expected pd.DatetimeIndex or pd.RangeIndex on data, found <class 'pandas.core.indexes.base.Index'>

Maybe the check can be relaxed to non-consecutive integer index?
Also note that even if casting the index above to RangeIndex, the model will throw a warning about not finding a TimeIndex in the data, which I think is expected if you have a RandeIndex already.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions