Skip to content

__repr__ for OpenML objects are not protected against missing class attributed #1058

@Neeratyoy

Description

@Neeratyoy

Description

The __repr__ print for OpenML objects is called from here. The _get_repr_body_fields function contains formatters for printing each object. However, if for certain reasons, some of the attributes are missing the print fails by throwing an error, while other functions of the API may work as-is. This can be a confusing behaviour for users.

Having checks to catch and handle such errors in _get_repr_body_fields will be useful to have.

Steps/Code to Reproduce

Representative example:

import openml
task = openml.tasks.get_task(146806)   
print(task)  # fails

Expected Results

OpenML Classification Task
==========================
Task Type Description: https://www.openml.org/tt/TaskType.SUPERVISED_CLASSIFICATION
Task ID..............: 146806
Task URL.............: https://www.openml.org/t/146806
Estimation Procedure.: holdout
Target Feature.......: label
# of Classes.........: 2
Cost Matrix..........: Available

Actual Results

TypeError: object of type 'NoneType' has no len()

Versions

OpenML 0.12.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good First IssueIssues suitable for people new to contributing to openml-python!enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions