Skip to content

TypeError raised by trying to get the __repr__ of a locally created task #1100

@PGijsbers

Description

@PGijsbers

When creating a task locally the __repr__ function raises a TypeError due to the class_labels attribute being None. This persists even after publishing it, which makes exposure of this bug more prevalent (because the task.publish() returns itself which invokes __repr__ if ran in an interactive shell without assigning the result to a variable):

import openml
openml.config.start_configuration_for_example()
t = openml.tasks.create_task(openml.tasks.task.TaskType.SUPERVISED_CLASSIFICATION, 128, 2, "class", "weighted_recall")
t.publish()
>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\repositories\openml-python\openml\base.py", line 19, in __repr__
    body_fields = self._get_repr_body_fields()
  File "D:\repositories\openml-python\openml\tasks\task.py", line 101, in _get_repr_body_fields
    fields["# of Classes"] = len(getattr(self, "class_labels"))
TypeError: object of type 'NoneType' has no len()

Suggested expected behavior: leave it out of the __repr__ if class_labels is None, i.e. extend the check of task#100 to skip assignment if class_labels is None. I don't think it's worth the added complexity to support an accurate class_labels in this niche scenario.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions