Skip to content

Refactor OpenMLEvaluation to use dataclass (Fixes #1540)#1701

Open
Sumitb09 wants to merge 3 commits intoopenml:mainfrom
Sumitb09:refactor-openml-evaluation-dataclass
Open

Refactor OpenMLEvaluation to use dataclass (Fixes #1540)#1701
Sumitb09 wants to merge 3 commits intoopenml:mainfrom
Sumitb09:refactor-openml-evaluation-dataclass

Conversation

@Sumitb09
Copy link

@Sumitb09 Sumitb09 commented Mar 7, 2026

Fixes #1540

Summary

Refactored the OpenMLEvaluation class to use Python's @dataclass decorator to simplify the class implementation and reduce boilerplate code.

Changes

  • Converted OpenMLEvaluation into a @dataclass.
  • Replaced manual attribute assignments with dataclass field definitions.
  • Used asdict() for dictionary conversion in _to_dict.
  • Added default values for optional fields (value, values, and array_data) to maintain compatibility with existing usage.
  • Ensured type hints follow modern Python standards (list instead of typing.List).

Benefits

  • Cleaner and more maintainable code.
  • Reduced boilerplate for attribute initialization.
  • Improved readability and type safety.

Testing

  • Ran black for formatting.
  • Ran ruff check --fix for linting.
  • Executed full test suite with pytest.

All tests pass successfully.

Before

The class relied on manual initialization and attribute assignments.

After

The class now uses Python's dataclass functionality, automatically generating __init__, __repr__, and other utility methods.

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.

[ENH] Refactor OpenMLEvaluation to Use Dataclass

1 participant