Skip to content

Commit

Permalink
Edit from_protobuf to use the total executions and failures
Browse files Browse the repository at this point in the history
  • Loading branch information
pecop2 committed Feb 22, 2022
1 parent 5495454 commit cbe843f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 10 additions & 2 deletions src/whylogs/core/statistics/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,11 @@ def from_protobuf(msg: ValueConstraintMsg) -> "ValueConstraint":
else:
val = msg.value

return ValueConstraint(msg.op, value=val, regex_pattern=regex_pattern, apply_function=apply_function, name=name, verbose=msg.verbose)
constraint = ValueConstraint(msg.op, value=val, regex_pattern=regex_pattern, apply_function=apply_function, name=name, verbose=msg.verbose)
constraint.total = msg.total
constraint.failures = msg.failures

return constraint

def to_protobuf(self) -> ValueConstraintMsg:
set_vals_message = None
Expand Down Expand Up @@ -1203,9 +1207,13 @@ def from_protobuf(msg: MultiColumnValueConstraintMsg) -> "MultiColumnValueConstr
ref_cols = "all"
else:
raise ValueError("MultiColumnValueConstraintMsg should contain one of the attributes: value_set, value or reference_columns, but none were found")
return MultiColumnValueConstraint(
mcv_constraint = MultiColumnValueConstraint(
dependent_cols, msg.op, value=value, reference_columns=ref_cols, name=name, internal_dependent_cols_op=internal_op, verbose=msg.verbose
)
mcv_constraint.total = msg.total
mcv_constraint.failures = msg.failures

return mcv_constraint

def to_protobuf(self) -> MultiColumnValueConstraintMsg:
value = None
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/core/statistics/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2946,7 +2946,7 @@ def test_multicolumn_value_constraints_serialization_deserialization():
assert sum_of_values["verbose"] is False


def test_value_constraints_report_serialization(local_config_path, df_lending_club):
def test_value_constraints_executions_serialization(local_config_path, df_lending_club):

df = pd.DataFrame({"col1": list(range(100)), "col2": list(range(149, 49, -1))})

Expand All @@ -2965,9 +2965,11 @@ def test_value_constraints_report_serialization(local_config_path, df_lending_cl
report = dc.report()

val_constraint_proto = val_constraint.to_protobuf()
assert report[0][1][0][1] == val_constraint_proto.total == 100
assert report[0][1][0][2] == val_constraint_proto.failures == 90
val_constraint_deser = ValueConstraint.from_protobuf(val_constraint_proto)
assert report[0][1][0][1] == val_constraint_proto.total == val_constraint_deser.total == 100
assert report[0][1][0][2] == val_constraint_proto.failures == val_constraint_deser.failures == 90

mc_val_constraint_proto = mc_val_constraint.to_protobuf()
assert report[1][1] == mc_val_constraint_proto.total == 100
assert report[1][2] == mc_val_constraint_proto.failures == 75
mc_val_constraint_deser = MultiColumnValueConstraint.from_protobuf(mc_val_constraint_proto)
assert report[1][1] == mc_val_constraint_proto.total == mc_val_constraint_deser.total == 100
assert report[1][2] == mc_val_constraint_proto.failures == mc_val_constraint_deser.failures == 75

0 comments on commit cbe843f

Please sign in to comment.