Refactor/recommendation dataframes#832
Open
AdrianSosic wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the discrete recommendation pipeline to return recommended candidates directly as a pd.DataFrame row subset (instead of a pd.Index), reducing reliance on pandas index semantics and removing a redundant re-selection step in callers. This aligns the recommendation API with upcoming SubspaceDiscrete refactoring work aimed at scalability and backend flexibility.
Changes:
- Switched
_recommend_discrete(and helper routines) across recommenders from returningpd.Indexto returning apd.DataFramesubset ofcandidates_exp. - Updated call sites (notably
PureRecommenderdispatch andNaiveRecommender) to work with returned DataFrames instead of re-selecting by index. - Updated docstrings and changelog entry to reflect the new return type/semantics.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
CHANGELOG.md |
Documents the discrete recommendation return-type change. |
baybe/recommenders/pure/nonpredictive/sampling.py |
Returns candidates_exp.iloc[...] directly from discrete sampling. |
baybe/recommenders/pure/nonpredictive/clustering.py |
Returns candidates_exp.iloc[...] directly from discrete clustering selection. |
baybe/recommenders/pure/bayesian/botorch/discrete.py |
Propagates DataFrame return type through subset/non-subset discrete BoTorch routines. |
baybe/recommenders/pure/bayesian/botorch/core.py |
Updates the BoTorch recommender’s _recommend_discrete contract to return a DataFrame. |
baybe/recommenders/pure/base.py |
Updates the base discrete recommendation flow to treat _recommend_discrete as returning a DataFrame (no re-selection step). |
baybe/recommenders/naive.py |
Adapts hybrid naive recommender logic to consume the discrete recommendation DataFrame. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -129,7 +129,7 @@ def _recommend_discrete( | |||
| selection = self._make_selection_default(model, candidates_scaled) | |||
|
|
|||
| # Convert positional indices into DataFrame indices and return result | |||
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.
Refactors the return types of the discrete recommendation engine, as a preparation for #793.
The
pd.Indexreturned by_recommend_discreteand its helpers has two structural downsides:Switching to returning a
DataFramesubselection directly is the natural fix – and it is straightforward to achieve because the intermediate index was never necessary in the first place: the helpers already havecandidates_expin scope and callers were simply using the index to re-select the same rows immediately after. It is a legacy mechanism from times where search spaces tracked recommendation metadata.