Skip to content

Commit

Permalink
Merge pull request #163 from whylabs/dev/andy/serialization
Browse files Browse the repository at this point in the history
Handle None case in Confusion matrix merging
  • Loading branch information
lalmei committed Feb 24, 2021
2 parents 946c15e + 468b93d commit 73abc56
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.3.3-dev0
current_version = 0.3.3-dev1
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def setup(app):
# built documents.
#
# The short X.Y version.
version = "0.3.3-dev0"
version = "0.3.3-dev1"
# The full version, including alpha/beta/rc tags.
release = "" # Is set by calling `setup.py docs`

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[metadata]
name = whylogs
version = 0.3.3-dev0
version = 0.3.3-dev1
description = Profile and monitor your ML data pipeline end-to-end
author = WhyLabs.ai
author-email = support@whylabs.ai
Expand Down
2 changes: 1 addition & 1 deletion src/whylogs/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""WhyLabs version number."""

__version__ = "0.3.3-dev0"
__version__ = "0.3.3-dev1"
6 changes: 5 additions & 1 deletion src/whylogs/core/metrics/model_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class ModelMetrics:
confusion_matrix (ConfusionMatrix): ConfusionMatrix which keeps it track of counts with NumberTracker
"""

def __init__(self, confusion_matrix: ConfusionMatrix = ConfusionMatrix()):
def __init__(self, confusion_matrix: ConfusionMatrix = None):
if confusion_matrix is None:
confusion_matrix = ConfusionMatrix()
self.confusion_matrix = confusion_matrix

def to_protobuf(self, ) -> ModelMetricsMessage:
Expand Down Expand Up @@ -61,5 +63,7 @@ def merge(self, other):
return self
if other.confusion_matrix is None:
# TODO: return a copy instead
return self
if self.confusion_matrix is None:
return other
return ModelMetrics(confusion_matrix=self.confusion_matrix.merge(other.confusion_matrix))
20 changes: 13 additions & 7 deletions tests/unit/core/metrics/test_model_metrics.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@

import pytest
import numpy as np
from sklearn.utils.multiclass import type_of_target

from whylogs.core.metrics.model_metrics import ModelMetrics


Expand All @@ -26,7 +21,6 @@ def tests_model_metrics():


def tests_model_metrics_to_protobuf():

mod_met = ModelMetrics()

targets_1 = ["cat", "dog", "pig"]
Expand All @@ -39,4 +33,16 @@ def tests_model_metrics_to_protobuf():

message = mod_met.to_protobuf()

read_mod_met = ModelMetrics.from_protobuf(message)
ModelMetrics.from_protobuf(message)


def test_merge_none():
metrics = ModelMetrics()
metrics.merge(None)


def test_merge_metrics_with_none_confusion_matrix():
metrics = ModelMetrics()
other = ModelMetrics()
other.confusion_matrix = None
metrics.merge(other)

0 comments on commit 73abc56

Please sign in to comment.