Skip to content

Commit

Permalink
Include timestamp in log_regression_metrics (#1578)
Browse files Browse the repository at this point in the history
## Description

Include timestamp in `log_regression_metrics()` when `log_full_data` is
`False`.

- [ ] I have reviewed the [Guidelines for Contributing](CONTRIBUTING.md)
and the [Code of Conduct](CODE_OF_CONDUCT.md).
  • Loading branch information
richard-rogers authored Oct 23, 2024
1 parent b364445 commit c9b9b8b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions python/tests/core/test_model_performance_metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
from datetime import datetime, timedelta, timezone
from logging import getLogger

import numpy as np
Expand Down Expand Up @@ -240,6 +241,26 @@ def test_profile_write_top_level_api_back_compat():
assert results2.view().get_column(prediction_column) is None


def test_regression_metrics_timestamp():
input_rows = 2
prediction_column = "col3"
target_column = "col3.ground_truth"
number_of_classes = 2
d = {
"col1": [i for i in range(input_rows)],
"col2": [i * i * 1.1 for i in range(input_rows)],
prediction_column: [f"x{str(i%number_of_classes)}" for i in range(input_rows)],
target_column: [f"x{str((i+1)%number_of_classes)}" for i in range(input_rows)],
}

df = pd.DataFrame(data=d)
timestamp = datetime.now(timezone.utc) - timedelta(days=7)
results = log_regression_metrics(
df, target_column="col1", prediction_column="col2", log_full_data=False, dataset_timestamp=timestamp
)
assert results.profile().dataset_timestamp == timestamp


def test_profile_top_level_api_segmented_performance():
input_rows = 10
prediction_column = "col3"
Expand Down
2 changes: 2 additions & 0 deletions python/whylogs/api/logger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ def _log_with_metrics(
results = log(pandas=data, schema=schema, dataset_timestamp=dataset_timestamp)
else:
results = ProfileResultSet(DatasetProfile(schema=schema))
if dataset_timestamp is not None:
results.set_dataset_timestamp(dataset_timestamp)

results.add_model_performance_metrics(metrics)
return results
Expand Down

0 comments on commit c9b9b8b

Please sign in to comment.