Skip to content

[OPIK-668]: BaseMetric safer defaults #1826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sdks/python/src/opik/evaluation/metrics/base_metric.py
Copy link
Collaborator

Choose a reason for hiding this comment

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

Test coverage?

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BaseMetric(abc.ABC):
from this class and implement the abstract methods.

Args:
name: The name of the metric.
name: The name of the metric. If not provided, uses the class name.
track: Whether to track the metric. Defaults to True.

Example:
Expand All @@ -33,8 +33,8 @@ class BaseMetric(abc.ABC):
>>> )
"""

def __init__(self, name: str, track: bool = True) -> None:
self.name = name
def __init__(self, name: str | None = None, track: bool = True) -> None:
self.name = name if name is not None else self.__class__.__name__
Comment on lines +36 to +37
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe the following would be enough:

def __init__(self, name: str = None, track: bool = True) -> None:
        self.name = name if name is not None else self.__class__.__name__

Or even better:

    def __init__(self, name: str = __class__.__name__, track: bool = True) -> None:
        self.name = name

Copy link
Collaborator

@alexkuzmik alexkuzmik Apr 29, 2025

Choose a reason for hiding this comment

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

@ldaugusto @andrescrz
BaseMetric is not supposed to be instantiated directly, it's a base for other metric classes. So, there is no point in adding a default value to it at all, subclasses will have their own default names anyway.

I suggest closing the PR

self.track = track

config = opik_config.OpikConfig()
Expand Down
Loading