Narwhalify model layer - #913
Open
AdrianSosic wants to merge 9 commits into
Open
Conversation
AdrianSosic
marked this pull request as ready for review
September 7, 2026 11:05
AdrianSosic
requested review from
fabianliebig and
myrazma
and
a lite review from Copilot
September 7, 2026 11:05
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A confirmed regression in Surrogate.posterior_stats uses vals.numpy() instead of a safe CPU conversion, which can raise at runtime when tensors are not on CPU.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR continues the “narwhalification” effort by updating the modeling stack (objectives → surrogates → acquisition functions → Bayesian recommenders/campaign APIs) to accept/return Narwhals-compatible dataframe/series inputs, reducing direct pandas coupling in the model layer.
Changes:
- Switch many model-layer interfaces from
pd.DataFrameto Narwhals typing (IntoDataFrame,IntoDataFrameT,IntoSeries) and usenarwhals.stable.v2conversions internally. - Refactor objective missing-value handling to a private, backend-preserving helper (
Objective._handle_missing_values). - Update surrogate posterior statistics and acquisition evaluation paths to return backend-native objects with index preservation helpers.
File summaries
| File | Description |
|---|---|
| CHANGELOG.md | Document breaking change: Objective.handle_missing_values made private. |
| baybe/surrogates/gaussian_process/presets/hvarfner.py | Narwhals-typed measurements for GP component factories. |
| baybe/surrogates/gaussian_process/presets/edbo.py | Narwhals-typed measurements for kernel/likelihood factories. |
| baybe/surrogates/gaussian_process/presets/edbo_smoothed.py | Narwhals-typed measurements for smoothed preset factories. |
| baybe/surrogates/gaussian_process/presets/chen.py | Narwhals-typed measurements for Chen kernel factory. |
| baybe/surrogates/gaussian_process/presets/botorch.py | Narwhals-typed measurements for BoTorch preset kernel factory. |
| baybe/surrogates/gaussian_process/presets/baybe.py | Narwhals-typed measurements across BayBE preset factories. |
| baybe/surrogates/gaussian_process/core.py | Store GP model context measurements as nw.DataFrame. |
| baybe/surrogates/gaussian_process/components/mean.py | Narwhals-typed measurements for mean factories. |
| baybe/surrogates/gaussian_process/components/likelihood.py | Narwhals-typed measurements for likelihood factories. |
| baybe/surrogates/gaussian_process/components/kernel.py | Narwhals-typed measurements across kernel factory protocols/implementations. |
| baybe/surrogates/gaussian_process/components/generic.py | Update GP component factory protocol to accept Narwhals-compatible dataframes. |
| baybe/surrogates/gaussian_process/components/fit_criterion.py | Narwhals-typed measurements in fit-criterion factory. |
| baybe/surrogates/composite.py | Use Narwhals conversions during per-quantity fitting and horizontal concat of posterior stats. |
| baybe/surrogates/base.py | Accept Narwhals inputs for fit/posterior APIs; return backend-native posterior stats with index copying. |
| baybe/recommenders/pure/bayesian/base.py | Pass Narwhals-compatible frames through Bayesian recommender training/acqf setup and acquisition evaluation. |
| baybe/recommenders/naive.py | Stop forcing pandas conversion when delegating to Bayesian recommender acqf setup. |
| baybe/objectives/base.py | Introduce private, backend-preserving _handle_missing_values; update dataframe utilities usage. |
| baybe/campaign.py | Widen campaign acquisition/pending-experiments typing to Narwhals-compatible frames/series. |
| baybe/acquisition/base.py | Return backend-native series from acquisition evaluation with index copying. |
| baybe/acquisition/acqfs.py | Return integration points in the configured default dataframe backend via Narwhals conversion. |
| baybe/acquisition/_builder.py | Make builder generic over dataframe backend and preserve backend in target-config selection. |
Review details
- Files reviewed: 22/22 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
AdrianSosic
force-pushed
the
refactor/narwhalify_surrogate_layer
branch
2 times, most recently
from
September 8, 2026 13:39
cdb7e1a to
a731147
Compare
AdrianSosic
force-pushed
the
dev/candidates
branch
from
September 8, 2026 14:07
fa9783b to
3fc26cd
Compare
AdrianSosic
force-pushed
the
refactor/narwhalify_surrogate_layer
branch
2 times, most recently
from
September 8, 2026 14:39
3ce7882 to
742adde
Compare
Hash computation and helper calls remain pandas-based for now
The register_hooks mechanism currently requires the types to be defined at runtime
AdrianSosic
force-pushed
the
refactor/narwhalify_surrogate_layer
branch
from
September 10, 2026 12:48
742adde to
03d6bf9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extends the narwhalification series to the surrogates, GP component factories, acquisition functions, and the Bayesian recommender layer.