Skip to content

Refactor/recommendation dataframes#832

Open
AdrianSosic wants to merge 2 commits into
dev/candidatesfrom
refactor/recommendation_dataframes
Open

Refactor/recommendation dataframes#832
AdrianSosic wants to merge 2 commits into
dev/candidatesfrom
refactor/recommendation_dataframes

Conversation

@AdrianSosic

@AdrianSosic AdrianSosic commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Refactors the return types of the discrete recommendation engine, as a preparation for #793.

The pd.Index returned by _recommend_discrete and its helpers has two structural downsides:

Switching to returning a DataFrame subselection 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 have candidates_exp in 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.

@AdrianSosic AdrianSosic added this to the 0.16.0 milestone Jun 18, 2026
@AdrianSosic AdrianSosic self-assigned this Jun 18, 2026
Copilot AI review requested due to automatic review settings June 18, 2026 12:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 returning pd.Index to returning a pd.DataFrame subset of candidates_exp.
  • Updated call sites (notably PureRecommender dispatch and NaiveRecommender) 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants