Skip to content

Commit 645ef01

Browse files
[ENH] Improve NotImplementedError Messages (#1574)
#### Metadata * Reference Issue: fixes #1537
1 parent 5d3cf0c commit 645ef01

6 files changed

Lines changed: 70 additions & 12 deletions

File tree

openml/datasets/dataset.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,11 @@ def _get_arff(self, format: str) -> dict: # noqa: A002
420420
file_size = filepath.stat().st_size
421421
if file_size > MB_120:
422422
raise NotImplementedError(
423-
f"File {filename} too big for {file_size}-bit system ({bits} bytes).",
423+
f"File '{filename}' ({file_size / 1e6:.1f} MB)"
424+
f"exceeds the maximum supported size of 120 MB. "
425+
f"This limitation applies to {bits}-bit systems. "
426+
f"Large dataset handling is currently not fully supported. "
427+
f"Please consider using a smaller dataset"
424428
)
425429

426430
if format.lower() == "arff":
@@ -780,7 +784,12 @@ def get_data( # noqa: C901
780784
# All the assumptions below for the target are dependant on the number of targets being 1
781785
n_targets = len(target_names)
782786
if n_targets > 1:
783-
raise NotImplementedError(f"Number of targets {n_targets} not implemented.")
787+
raise NotImplementedError(
788+
f"Multi-target prediction is not yet supported."
789+
f"Found {n_targets} target columns: {target_names}. "
790+
f"Currently, only single-target datasets are supported. "
791+
f"Please select a single target column."
792+
)
784793

785794
target_name = target_names[0]
786795
x = data.drop(columns=[target_name])

openml/runs/functions.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,12 @@ def _run_task_get_arffcontent_parallel_helper( # noqa: PLR0913
755755
test_x = None
756756
test_y = None
757757
else:
758-
raise NotImplementedError(task.task_type)
758+
raise NotImplementedError(
759+
f"Task type '{task.task_type}' is not supported. "
760+
f"Only OpenMLSupervisedTask and OpenMLClusteringTask are currently implemented. "
761+
f"Task details: task_id={getattr(task, 'task_id', 'unknown')}, "
762+
f"task_class={task.__class__.__name__}"
763+
)
759764

760765
config.logger.info(
761766
f"Going to run model {model!s} on "
@@ -982,7 +987,13 @@ def obtain_field(xml_obj, fieldname, from_server, cast=None): # type: ignore
982987
if "predictions" not in files and from_server is True:
983988
task = openml.tasks.get_task(task_id)
984989
if task.task_type_id == TaskType.SUBGROUP_DISCOVERY:
985-
raise NotImplementedError("Subgroup discovery tasks are not yet supported.")
990+
raise NotImplementedError(
991+
f"Subgroup discovery tasks are not yet supported. "
992+
f"Task ID: {task_id}. Please check the OpenML documentation"
993+
f"for supported task types. "
994+
f"Currently supported task types: Classification, Regression,"
995+
f"Clustering, and Learning Curve."
996+
)
986997

987998
# JvR: actually, I am not sure whether this error should be raised.
988999
# a run can consist without predictions. But for now let's keep it
@@ -1282,7 +1293,12 @@ def format_prediction( # noqa: PLR0913
12821293
if isinstance(task, OpenMLRegressionTask):
12831294
return [repeat, fold, index, prediction, truth]
12841295

1285-
raise NotImplementedError(f"Formatting for {type(task)} is not supported.")
1296+
raise NotImplementedError(
1297+
f"Formatting for {type(task)} is not supported."
1298+
f"Supported task types: OpenMLClassificationTask, OpenMLRegressionTask,"
1299+
f"and OpenMLLearningCurveTask. "
1300+
f"Please ensure your task is one of these types."
1301+
)
12861302

12871303

12881304
def delete_run(run_id: int) -> bool:

openml/runs/run.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,12 @@ def _generate_arff_dict(self) -> OrderedDict[str, Any]:
479479
]
480480

481481
else:
482-
raise NotImplementedError(f"Task type {task.task_type!s} is not yet supported.")
482+
raise NotImplementedError(
483+
f"Task type '{task.task_type}' is not yet supported. "
484+
f"Supported task types: Classification, Regression, Clustering, Learning Curve. "
485+
f"Task ID: {task.task_id}. "
486+
f"Please check the OpenML documentation for supported task types."
487+
)
483488

484489
return arff_dict
485490

openml/study/study.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,23 @@ def _to_dict(self) -> dict[str, dict]:
176176

177177
def push_tag(self, tag: str) -> None:
178178
"""Add a tag to the study."""
179-
raise NotImplementedError("Tags for studies is not (yet) supported.")
179+
raise NotImplementedError(
180+
"Tag management for studies is not yet supported. "
181+
"The OpenML Python SDK does not currently provide functionality"
182+
"for adding tags to studies."
183+
"For updates on this feature, please refer to the GitHub issues at: "
184+
"https://github.com/openml/openml-python/issues"
185+
)
180186

181187
def remove_tag(self, tag: str) -> None:
182188
"""Remove a tag from the study."""
183-
raise NotImplementedError("Tags for studies is not (yet) supported.")
189+
raise NotImplementedError(
190+
"Tag management for studies is not yet supported. "
191+
"The OpenML Python SDK does not currently provide functionality"
192+
"for removing tags from studies. "
193+
"For updates on this feature, please refer to the GitHub issues at: "
194+
"https://github.com/openml/openml-python/issues"
195+
)
184196

185197

186198
class OpenMLStudy(BaseStudy):

openml/tasks/functions.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,12 @@ def _create_task_from_xml(xml: str) -> OpenMLTask:
528528
TaskType.LEARNING_CURVE: OpenMLLearningCurveTask,
529529
}.get(task_type)
530530
if cls is None:
531-
raise NotImplementedError(f"Task type {common_kwargs['task_type']} not supported.")
531+
raise NotImplementedError(
532+
f"Task type '{common_kwargs['task_type']}' is not supported. "
533+
f"Supported task types: SUPERVISED_CLASSIFICATION,"
534+
f"SUPERVISED_REGRESSION, CLUSTERING, LEARNING_CURVE."
535+
f"Please check the OpenML documentation for available task types."
536+
)
532537
return cls(**common_kwargs) # type: ignore
533538

534539

@@ -584,7 +589,13 @@ def create_task(
584589
elif task_type == TaskType.SUPERVISED_REGRESSION:
585590
task_cls = OpenMLRegressionTask # type: ignore
586591
else:
587-
raise NotImplementedError(f"Task type {task_type:d} not supported.")
592+
raise NotImplementedError(
593+
f"Task type ID {task_type:d} is not supported. "
594+
f"Supported task type IDs: {TaskType.SUPERVISED_CLASSIFICATION.value},"
595+
f"{TaskType.SUPERVISED_REGRESSION.value}, "
596+
f"{TaskType.CLUSTERING.value}, {TaskType.LEARNING_CURVE.value}. "
597+
f"Please refer to the TaskType enum for valid task type identifiers."
598+
)
588599

589600
return task_cls(
590601
task_type_id=task_type,

openml/tasks/task.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,12 @@ def get_X_and_y(self) -> tuple[pd.DataFrame, pd.Series | pd.DataFrame | None]:
291291
TaskType.SUPERVISED_REGRESSION,
292292
TaskType.LEARNING_CURVE,
293293
):
294-
raise NotImplementedError(self.task_type)
294+
raise NotImplementedError(
295+
f"Task type '{self.task_type}' is not implemented for get_X_and_y(). "
296+
f"Supported types: SUPERVISED_CLASSIFICATION, SUPERVISED_REGRESSION,"
297+
f"LEARNING_CURVE."
298+
f"Task ID: {getattr(self, 'task_id', 'unknown')}. "
299+
)
295300

296301
X, y, _, _ = dataset.get_data(target=self.target_name)
297302
return X, y
@@ -383,7 +388,7 @@ def __init__( # noqa: PLR0913
383388
self.cost_matrix = cost_matrix
384389

385390
if cost_matrix is not None:
386-
raise NotImplementedError("Costmatrix")
391+
raise NotImplementedError("Costmatrix functionality is not yet implemented.")
387392

388393

389394
class OpenMLRegressionTask(OpenMLSupervisedTask):

0 commit comments

Comments
 (0)