diff --git a/ax/adapter/cross_validation.py b/ax/adapter/cross_validation.py index e638367ffc1..45fa2cd9ade 100644 --- a/ax/adapter/cross_validation.py +++ b/ax/adapter/cross_validation.py @@ -240,12 +240,13 @@ def _efficient_loo_cross_validate( # This is a known limitation for fully Bayesian models and models with # non-Gaussian posteriors (such as PFNs). # Shape: n x 1 x m - loo_means = posterior.mixture_mean.detach().cpu().numpy() - loo_vars = posterior.mixture_variance.detach().cpu().numpy() + # Use .copy() to ensure arrays are writeable (numpy returns read-only views) + loo_means = posterior.mixture_mean.detach().cpu().numpy().copy() + loo_vars = posterior.mixture_variance.detach().cpu().numpy().copy() else: # Shape: n x 1 x m - loo_means = posterior.mean.detach().cpu().numpy() - loo_vars = posterior.variance.detach().cpu().numpy() + loo_means = posterior.mean.detach().cpu().numpy().copy() + loo_vars = posterior.variance.detach().cpu().numpy().copy() # Squeeze out the q dimension: n x 1 x m -> n x m loo_means = loo_means.squeeze(1) diff --git a/ax/core/data.py b/ax/core/data.py index 0ebd6fdc01a..56a89036611 100644 --- a/ax/core/data.py +++ b/ax/core/data.py @@ -195,9 +195,13 @@ def _safecast_df(cls: type[TData], df: pd.DataFrame) -> pd.DataFrame: if col in df.columns.values and coltype is not Any: # Pandas timestamp handlng is weird dtype = "datetime64[ns]" if coltype is pd.Timestamp else coltype - if (dtype != dtypes[col]) and not ( - coltype is int and df.loc[:, col].isnull().any() - ): + current_dtype = dtypes[col] + # Handle StringDtype -> object conversion (pandas 2.0+ compatibility) + needs_cast = ( + isinstance(current_dtype, pd.StringDtype) + or (dtype != current_dtype) + ) and not (coltype is int and df.loc[:, col].isnull().any()) + if needs_cast: df[col] = df[col].astype(dtype) df.reset_index(inplace=True, drop=True) return df