Skip to content

Conversation

@rohansen856
Copy link

I have Refactored the OpenMLEvaluation class from a traditional Python class to use the @dataclass decorator to reduce boilerplate code and improve code maintainability.

Metadata

Details

Edited the OpenMLEvaluation class in openml\evaluations\evaluation.py to use @dataclass decorator. This significantly reduces the boilerplate code in the following places:

  • Instance Variable Definitions

Before:

def__init__( self, run_id: int, task_id: int, setup_id: int, flow_id: int, flow_name: str, data_id: int, data_name: str, function: str, upload_time: str, uploader: int, uploader_name: str, value: float|None, values: list[float] |None, array_data: str|None=None, ): self.run_id=run_idself.task_id=task_idself.setup_id=setup_idself.flow_id=flow_idself.flow_name=flow_nameself.data_id=data_idself.data_name=data_nameself.function=functionself.upload_time=upload_timeself.uploader=uploaderself.uploader_name=uploader_nameself.value=valueself.values=valuesself.array_data=array_data

After:

run_id: inttask_id: intsetup_id: intflow_id: intflow_name: strdata_id: intdata_name: strfunction: strupload_time: struploader: intuploader_name: strvalue: float|Nonevalues: list[float] |Nonearray_data: str|None=None
  • _to_dict Method Simplification

Before:

def_to_dict(self) ->dict: return{"run_id": self.run_id, "task_id": self.task_id, "setup_id": self.setup_id, "flow_id": self.flow_id, "flow_name": self.flow_name, "data_id": self.data_id, "data_name": self.data_name, "function": self.function, "upload_time": self.upload_time, "uploader": self.uploader, "uploader_name": self.uploader_name, "value": self.value, "values": self.values, "array_data": self.array_data, }

After:

def_to_dict(self) ->dict: returnasdict(self)

All tests are passing with accordnce to the changes:

PS C:\Users\ASUS\Documents\work\opensource\openml-python> pytest tests/test_evaluations/ ======================================= test session starts ======================================= platform win32 -- Python 3.14.0, pytest-9.0.2, pluggy-1.6.0 rootdir: C:\Users\ASUS\Documents\work\opensource\openml-python configfile: pyproject.toml plugins: anyio-4.12.0, flaky-3.8.1, asyncio-1.3.0, cov-7.0.0, mock-3.15.1, rerunfailures-16.1, timeout-2.4.0, xdist-3.8.0, requests-mock-1.12.1 asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function collected 13 items tests\test_evaluations\test_evaluation_functions.py ............ [ 92%] tests\test_evaluations\test_evaluations_example.py . [100%] ================================= 13 passed in 274.80s (0:04:34) ================================== 

Copy link

@geetu040geetu040 left a comment

Choose a reason for hiding this comment

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

In the order list, also fix the first item "Uploader Date" to "Upload Date"

"OpenML Run URL",
"Task ID",
"OpenML Task URL""Flow ID",
"OpenML Task URLFlow ID",

Choose a reason for hiding this comment

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

Suggested change
"OpenML Task URLFlow ID",
"OpenML Task URL",
"Flow ID",

Sign up for freeto 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.

2 participants

@rohansen856@geetu040