-
Notifications
You must be signed in to change notification settings - Fork 411
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
Added add_metrics method to MetricCollection #221
Added add_metrics method to MetricCollection #221
Conversation
Codecov Report
@@ Coverage Diff @@
## master #221 +/- ##
==========================================
- Coverage 96.78% 87.97% -8.81%
==========================================
Files 184 184
Lines 5976 5965 -11
==========================================
- Hits 5784 5248 -536
- Misses 192 717 +525
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -185,6 +147,51 @@ def persistent(self, mode: bool = True) -> None: | |||
for _, m in self.items(): | |||
m.persistent(mode) | |||
|
|||
def add_metrics(self, metrics: Union[Metric, Sequence[Metric], Dict[str, Metric]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def add_metrics(self, metrics: Union[Metric, Sequence[Metric], Dict[str, Metric]], | |
def append(self, metrics: Union[Metric, Sequence[Metric], Dict[str, Metric]], |
would it be a better name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to keep the name different. If we say append
it might imply that it won't work as extend
while here it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_metrics
seems more appropriate for a Collection.
if isinstance(metrics, Metric): | ||
# set compatible with original type expectations | ||
metrics = [metrics] | ||
if isinstance(metrics, Sequence): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand this is just copying what we had here before, but we should probably have Iterable
here instead of Sequence
as we doin't really care about indexing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but iterable does not have len, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not using len though, we are just directly converting to a list in the next line.
@@ -185,6 +147,51 @@ def persistent(self, mode: bool = True) -> None: | |||
for _, m in self.items(): | |||
m.persistent(mode) | |||
|
|||
def add_metrics(self, metrics: Union[Metric, Sequence[Metric], Dict[str, Metric]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be Mapping[str, Metrics]
, not Dict
+ similar a check below.
@@ -185,6 +147,51 @@ def persistent(self, mode: bool = True) -> None: | |||
for _, m in self.items(): | |||
m.persistent(mode) | |||
|
|||
def add_metrics(self, metrics: Union[Metric, Sequence[Metric], Dict[str, Metric]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to keep the name different. If we say append
it might imply that it won't work as extend
while here it does.
@IgorHoholko mind check the comments above? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ! Worth to increase the coverage slightly.
@@ -185,6 +147,51 @@ def persistent(self, mode: bool = True) -> None: | |||
for _, m in self.items(): | |||
m.persistent(mode) | |||
|
|||
def add_metrics(self, metrics: Union[Metric, Sequence[Metric], Dict[str, Metric]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_metrics
seems more appropriate for a Collection.
Fixes #203
Before submitting
What does this PR do?
add_metrics()
method for MetricCollection class.PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.
Did you have fun?
Make sure you had fun coding 🙃