Skip to content

Add CandidatesProtocol#800

Open
myrazma wants to merge 34 commits into
dev/candidatesfrom
feature/candidates_base
Open

Add CandidatesProtocol#800
myrazma wants to merge 34 commits into
dev/candidatesfrom
feature/candidates_base

Conversation

@myrazma

@myrazma myrazma commented May 13, 2026

Copy link
Copy Markdown
Collaborator

Prepares #796

  • Adds narwhals as a hard dependency for backend-agnostic dataframe operations
  • Introduces CandidatesProtocol along with ProductCandidates and TableCandidates classes for representing discrete candidate sets, backed by narwhals lazy frames
  • Adds DiscreteParameter.is_finite property and InfiniteSpaceError exception
  • Enables validation for extra columns in candidate tables

@myrazma myrazma marked this pull request as ready for review May 13, 2026 19:02
Copilot AI review requested due to automatic review settings May 13, 2026 19:02

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 introduces a new candidate-generation abstraction for discrete search spaces, adds Narwhals-based lazy dataframe conversion utilities, and wires in new hard dependencies (narwhals, polars) alongside tests to validate the new candidate classes.

Changes:

  • Added CandidatesProtocol plus ProductCandidates (cartesian product + constraints) and TableCandidates (user-provided table) for candidate handling.
  • Added Narwhals lazy dataframe conversion helpers (to_lazy_narwhals, from_lazy_narwhals).
  • Added dependencies and changelog entries, plus a new test module for candidates.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
baybe/searchspace/candidates.py New candidate protocol and implementations for product/table candidate generation.
baybe/utils/dataframe.py Adds Narwhals lazy/native conversion helpers.
baybe/exceptions.py Adds InfiniteSpaceError for operations requiring finite spaces.
tests/test_candidates.py New tests for ProductCandidates / TableCandidates.
pyproject.toml Adds narwhals and polars[pyarrow] as core dependencies.
uv.lock Updates lockfile to include new dependencies/versions.
CHANGELOG.md Documents the new dependencies and candidate system additions.
Comments suppressed due to low confidence (1)

tests/test_candidates.py:137

  • Pytest parametrizes parameter_names and constraint_names for this test, but test_product_candidates_creation does not accept these arguments. As written, pytest collection will error (“function uses no argument …”). Add the missing arguments to the signature or use indirect parametrization of the parameters/constraints fixtures.
@pytest.mark.parametrize(
    "parameter_names",
    [
        ["Num_disc_1", "Num_disc_2", "Fraction_2"],
        ["Categorical_1", "Num_disc_1"],
        ["Categorical_1", "Categorical_2", "Categorical_1_subset"],
    ],
    ids=["numerical", "mixed", "categorical"],
)
@pytest.mark.parametrize(
    "constraint_names",
    [
        [],
        ["DiscreteSumConstraint"],
        ["DiscreteExcludeConstraint"],
    ],
    ids=["no_constraint", "sum", "exclude"],
)
def test_product_candidates_creation(parameters, constraints):
    """ProductCandidates can be created with valid parameters and constraints."""
    candidates = ProductCandidates(parameters=parameters, constraints=constraints)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_candidates.py Outdated
Comment thread baybe/searchspace/candidates.py Outdated
Comment thread pyproject.toml
@Scienfitz

Copy link
Copy Markdown
Collaborator

is this PR related to any of the Issues 793 to 798?

@AdrianSosic

Copy link
Copy Markdown
Collaborator

is this PR related to any of the Issues 793 to 798?

Yes, to #796, but only as a preparation step. Will add it to description.

@Scienfitz, @AVHopp: Let me do a first round of polish before you start your review, will save us some unnecessary iterations

@Scienfitz Scienfitz marked this pull request as draft May 18, 2026 08:46
@Scienfitz

Copy link
Copy Markdown
Collaborator

please put PRs not ready fort review in draft

@AdrianSosic AdrianSosic changed the title Add CandidateProtocol and Base Candidate Classes Add CandidatesProtocol May 21, 2026
@AdrianSosic AdrianSosic force-pushed the feature/candidates_base branch from cc5829c to 3dfbbc4 Compare May 21, 2026 14:40
@AdrianSosic AdrianSosic marked this pull request as ready for review May 21, 2026 14:40
@AdrianSosic AdrianSosic force-pushed the feature/candidates_base branch from 3dfbbc4 to 6b59e42 Compare May 21, 2026 14:46

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

Copilot reviewed 11 out of 12 changed files in this pull request and generated 6 comments.

Comment thread baybe/searchspace/candidates.py
Comment thread baybe/utils/validation.py Outdated
Comment thread baybe/parameters/base.py
Comment thread tests/test_candidates.py
Comment thread AGENTS.md Outdated
Comment thread CHANGELOG.md Outdated
@AdrianSosic AdrianSosic changed the base branch from main to dev/candidates May 21, 2026 14:46
@AdrianSosic AdrianSosic self-assigned this May 22, 2026
@AdrianSosic AdrianSosic added new feature New functionality dev labels May 22, 2026
@AdrianSosic AdrianSosic added this to the Roadmap (no ETA) milestone May 22, 2026

@fabianliebig fabianliebig left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@AdrianSosic: Looks pretty good to me, I have a few questions but most of them are really mainly for my understanding and out of curiosity also regarding the upcoming changes. Just because planning and coding is rather different, there are potentially some comments that are obsolete because it's just a preparation PR so feel free to resolve if they don't make much sense to you :)

Comment thread baybe/parameters/base.py
Comment thread baybe/searchspace/candidates.py
Comment thread baybe/searchspace/candidates.py
@Scienfitz Scienfitz modified the milestones: Roadmap (no ETA), 0.16.0 Jun 2, 2026

@AVHopp AVHopp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some first thoughts and questions

Comment thread baybe/parameters/base.py
Comment thread baybe/searchspace/candidates.py
Comment thread baybe/searchspace/candidates.py
Comment thread baybe/searchspace/candidates.py
Comment thread baybe/utils/validation.py Outdated
Comment thread baybe/utils/validation.py
parameters: Sequence[Parameter],
numerical_measurements_must_be_within_tolerance: bool = False,
*,
allow_extra: bool = True,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

just to make sure: Previously, we actually allowed extra columns not related to any actual parameter, and we now make this very explicit, right?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yes, because especially in the context of a dataframe-spanned search space, this is extremely prone to (silent) errors otherwise! Should have done that much earlier, tbh. I'm even considering to turn the default into False now that I think about it. Would strictly be breaking change, but offering guard rails that should have been there from the very beginning 🤔 What do you think?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

False also feels more natural to me, and while we are on the dev branch we can anyway do whatever we want, so feel free to change it

Comment thread AGENTS.md
Comment thread CHANGELOG.md Outdated
@AdrianSosic AdrianSosic force-pushed the feature/candidates_base branch from dd395dd to ce97cfd Compare June 9, 2026 18:07
@AVHopp

AVHopp commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

@AdrianSosic I see that the tests are currently failing due to some overflow issue in the serialization tests, is this something new or do we simply need to rebase branches?

@AVHopp AVHopp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please fix failing test (via rebasing if that is the issue ideally), otherwise all gucci :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev new feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants