Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ax/adapter/cross_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions ax/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading