ValueError raised on cached function that does not occur on uncached

I have a function that I am using to fit a model in a Streamlit app, which includes a call to scikit-learn’s train_test_split, as is common.

@st.cache
def fit_model():

    X = data_merged[PRED_COLUMNS]
    target = data_merged.response
    x_train, x_valid, y_train, y_valid = train_test_split(
        X, target, test_size=0.2, random_state=42)

However, when I run the app, I get the following error:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Streamlit encountered an error while caching the body of fit_model(). This is likely due to a bug in /home/ubuntu/GitHub/models/app.py near line 187:

target = data_merged.response
x_train, x_valid, y_train, y_valid = train_test_split(
    X, target, test_size=0.2, random_state=42)

When I remove the cache decorator, this error does not occur and the model runs to completion. Given that the function that is failing is a common data processing function, I’m not sure what is causing this failure.