Skip to content

Add attach_runs/detach_runs to OpenMLStudy and attach_tasks/detach_tasks to OpenMLBenchmarkSuite - #1729

Open
N-Garai wants to merge 3 commits into
openml:mainfrom
N-Garai:feature/issue-1109-study-attach-runs
Open

Add attach_runs/detach_runs to OpenMLStudy and attach_tasks/detach_tasks to OpenMLBenchmarkSuite#1729
N-Garai wants to merge 3 commits into
openml:mainfrom
N-Garai:feature/issue-1109-study-attach-runs

Conversation

@N-Garai

@N-Garai N-Garai commented Aug 12, 2026

Copy link
Copy Markdown

Metadata

Details

  • What does this PR implement/fix? Adds instance methods attach_runs(run_ids) and detach_runs(run_ids) to OpenMLStudy, and attach_tasks(task_ids) and detach_tasks(task_ids) to OpenMLBenchmarkSuite. These methods delegate to the existing public module-level functions (openml.study.attach_to_study, openml.study.detach_from_study, openml.study.attach_to_suite, openml.study.detach_from_suite), update local object state, and raise ValueError if the object has not been published yet.

  • Why is this change necessary? The current API requires passing the study/suite ID back into a module-level function even when the object is already in hand. This is inconsistent with the object-oriented design of the rest of the SDK and makes iterative workflows (e.g., adding runs to a study as they complete on a cluster) unnecessarily verbose.

  • How can I reproduce the issue this PR is solving and its solution?

    • Before:
         openml.study.attach_to_study(study.id, [1, 2, 3])
    
    • After:
      study.attach_runs([1, 2, 3])
    

    The object methods behave identically to the module-level functions but operate on the instance directly.

  • Any other comments? Existing module-level functions are preserved for backward compatibility. New tests cover both successful attach/detach operations against the test server and ValueError guards for unpublished objects. All uploaded test entities are collected for removal using TestBase._mark_entity_for_removal().

…sks to OpenMLBenchmarkSuite

Implements openml#1109. Adds instance methods to study and suite objects so users
can call:
- study.attach_runs(run_ids)
- study.detach_runs(run_ids)
- suite.attach_tasks(task_ids)
- suite.detach_tasks(task_ids)

instead of the module-level:
- openml.study.attach_to_study(study_id, run_ids)

The new methods delegate to existing module-level functions, update local
state, and raise ValueError if the object has not been published. Existing
module-level functions are preserved for backward compatibility.
Copilot AI lite review requested due to automatic review settings August 12, 2026 14:55

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 adds instance-level convenience methods to the OpenML study/suite objects so callers can attach/detach runs/tasks directly on an OpenMLStudy / OpenMLBenchmarkSuite instance (instead of calling the module-level functions with IDs).

Changes:

  • Add OpenMLStudy.attach_runs() / OpenMLStudy.detach_runs() instance methods.
  • Add OpenMLBenchmarkSuite.attach_tasks() / OpenMLBenchmarkSuite.detach_tasks() instance methods.
  • Add test-server coverage for the new instance methods and for unpublished-object guards.

Reviewed changes

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

File Description
openml/study/study.py Adds the new instance methods for attaching/detaching runs/tasks on study/suite objects.
tests/test_study/test_study_functions.py Adds new test-server tests validating the instance methods and unpublished-object error guards.
Suppressed comments (2)

openml/study/study.py:328

  • openml.study.functions is an internal reference; prefer the public openml.study.detach_from_study function. Also, converting run_ids to a set avoids O(n*m) behavior when removing many run IDs from a large local list.
        result = openml.study.functions.detach_from_study(self.id, run_ids)
        if self.runs is not None:
            self.runs = [run_id for run_id in self.runs if run_id not in run_ids]
        return result

openml/study/study.py:451

  • Use the public openml.study.detach_from_suite function instead of the internal openml.study.functions reference. Converting task_ids to a set also avoids repeated linear membership checks when updating the local list.
        result = openml.study.functions.detach_from_suite(self.id, task_ids)
        if self.tasks is not None:
            self.tasks = [task_id for task_id in self.tasks if task_id not in task_ids]
        return result

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread openml/study/study.py Outdated
Comment on lines +299 to +301
result = openml.study.functions.attach_to_study(self.id, run_ids)
self.runs = (self.runs or []) + list(run_ids)
return result
Comment thread openml/study/study.py Outdated
Comment on lines +422 to +424
result = openml.study.functions.attach_to_suite(self.id, task_ids)
self.tasks = (self.tasks or []) + list(task_ids)
return result
Comment on lines +287 to +289
run_list_additional = openml.runs.list_runs(size=3, offset=5)
run_list_additional_ids = list(run_list_additional["run_id"])
attached_count = study.attach_runs(run_list_additional_ids)
…hecks

- Replace openml.study.functions.* with openml.study.* in all four methods
- Use set(run_ids) and set(task_ids) for O(1) membership checks in detach methods
Copilot AI review requested due to automatic review settings August 12, 2026 15:13

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Discussion] Add detach/attach run/task to study/suite object?

2 participants