Skip to content
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

Include timestamp in log_regression_metrics #1578

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
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
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
Loading