Skip to content

[ENH] Replace asserts with proper if else Exception handling#1589

Open
Omswastik-11 wants to merge 14 commits intoopenml:mainfrom
Omswastik-11:issue-1581
Open

[ENH] Replace asserts with proper if else Exception handling#1589
Omswastik-11 wants to merge 14 commits intoopenml:mainfrom
Omswastik-11:issue-1581

Conversation

@Omswastik-11
Copy link
Contributor

Fixes #1581

@Omswastik-11
Copy link
Contributor Author

Omswastik-11 commented Jan 2, 2026

Hi @fkiraly !! I would like to know you suggestion on this .

Screenshot 2026-01-02 133722

In openml\runs\run.py the _generate_arff_dict function is causing the above issue . so I created a new function _get_arff_attributes_for_task to reduce complexity is it ok ? or should I think of a alternate solution ?

@Omswastik-11 Omswastik-11 changed the title [MNT] Replace asserts with proper if else error handling [MNT] Replace asserts with proper if else Exception handling Jan 2, 2026
Copy link
Collaborator

@fkiraly fkiraly left a comment

Choose a reason for hiding this comment

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

Yes, looks reasonable for me for a first go, to isolate the if/else in a function.

More generally, from an architecture standpoint however, whenever I see a long list of if/elses on the argument class type, I think it is too high coupling and it should be either a method of the (task/argument) class or a visitor pattern.

Why: imagine you want to add a new task. Now you have to add another elif in all of these functions. This is absolutely not extensible.

This should be refactored - I would say, in another PR, after opening an issue with a plan - so the task itself, or a visitor, manages whatever is in the if/else.

@codecov-commenter
Copy link

codecov-commenter commented Jan 2, 2026

Codecov Report

❌ Patch coverage is 4.65116% with 41 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.72%. Comparing base (7feb2a3) to head (b8a7992).

Files with missing lines Patch % Lines
openml/runs/run.py 4.34% 22 Missing ⚠️
openml/runs/functions.py 7.14% 13 Missing ⚠️
openml/runs/trace.py 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1589      +/-   ##
==========================================
- Coverage   52.82%   52.72%   -0.10%     
==========================================
  Files          37       37              
  Lines        4371     4381      +10     
==========================================
+ Hits         2309     2310       +1     
- Misses       2062     2071       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fkiraly fkiraly changed the title [MNT] Replace asserts with proper if else Exception handling [ENH] Replace asserts with proper if else Exception handling Jan 2, 2026
@fkiraly fkiraly added enhancement module:Run OpenML concept labels Jan 2, 2026
@Omswastik-11 Omswastik-11 requested a review from fkiraly January 2, 2026 12:04
Copy link
Collaborator

@geetu040 geetu040 left a comment

Choose a reason for hiding this comment

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

Good, just ran the tests in tests/test_runs/ to be sure of the refactor, and it's green.
Ready to be merged!

Copilot AI review requested due to automatic review settings February 20, 2026 18:40
Copy link

Copilot AI left a comment

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 replaces assert-based validation in the openml.runs module with explicit exceptions, improving reliability (asserts can be stripped with Python -O) and providing clearer failure modes. It also refactors ARFF attribute construction into a dedicated helper to reduce duplication.

Changes:

  • Replaced multiple assert ... is not None validations with ValueError/TypeError raises across runs-related code paths.
  • Added OpenMLRun._get_arff_attributes_for_task() and used it from _generate_arff_dict() to centralize ARFF attribute generation.
  • Tightened runtime type checks for inputs derived from task data (y type in parallel helper).

Reviewed changes

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

File Description
openml/runs/trace.py Replaces asserts with explicit exceptions when parameters are unexpectedly missing.
openml/runs/run.py Adds a helper for task-dependent ARFF attributes; replaces flow-id assertion with explicit error.
openml/runs/functions.py Replaces several asserts with explicit exceptions in run/model initialization and run-list parsing.

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

Copilot AI review requested due to automatic review settings February 26, 2026 16:21
Copy link

Copilot AI left a comment

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 3 out of 3 changed files in this pull request and generated 2 comments.


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

Copilot AI review requested due to automatic review settings February 27, 2026 08:25
Copy link

Copilot AI left a comment

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 3 out of 3 changed files in this pull request and generated no new comments.


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

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MNT] Replace Assert Statements with Proper Exceptions

5 participants