proxyml 0.10.0__tar.gz → 0.11.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {proxyml-0.10.0 → proxyml-0.11.0}/PKG-INFO +5 -3
- {proxyml-0.10.0 → proxyml-0.11.0}/README.md +3 -1
- {proxyml-0.10.0 → proxyml-0.11.0}/pyproject.toml +2 -2
- {proxyml-0.10.0 → proxyml-0.11.0}/src/proxyml/__init__.py +6 -0
- {proxyml-0.10.0 → proxyml-0.11.0}/src/proxyml/client.py +99 -0
- {proxyml-0.10.0 → proxyml-0.11.0}/src/proxyml.egg-info/PKG-INFO +5 -3
- {proxyml-0.10.0 → proxyml-0.11.0}/src/proxyml.egg-info/requires.txt +1 -1
- {proxyml-0.10.0 → proxyml-0.11.0}/tests/test_client.py +59 -0
- {proxyml-0.10.0 → proxyml-0.11.0}/LICENSE +0 -0
- {proxyml-0.10.0 → proxyml-0.11.0}/setup.cfg +0 -0
- {proxyml-0.10.0 → proxyml-0.11.0}/src/proxyml/ci.py +0 -0
- {proxyml-0.10.0 → proxyml-0.11.0}/src/proxyml/local/__init__.py +0 -0
- {proxyml-0.10.0 → proxyml-0.11.0}/src/proxyml/local/challenger.py +0 -0
- {proxyml-0.10.0 → proxyml-0.11.0}/src/proxyml/schema_builder.py +0 -0
- {proxyml-0.10.0 → proxyml-0.11.0}/src/proxyml.egg-info/SOURCES.txt +0 -0
- {proxyml-0.10.0 → proxyml-0.11.0}/src/proxyml.egg-info/dependency_links.txt +0 -0
- {proxyml-0.10.0 → proxyml-0.11.0}/src/proxyml.egg-info/top_level.txt +0 -0
- {proxyml-0.10.0 → proxyml-0.11.0}/tests/test_ci.py +0 -0
- {proxyml-0.10.0 → proxyml-0.11.0}/tests/test_dependency_boundaries.py +0 -0
- {proxyml-0.10.0 → proxyml-0.11.0}/tests/test_local_challenger.py +0 -0
- {proxyml-0.10.0 → proxyml-0.11.0}/tests/test_schema_builder.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: proxyml
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0
|
|
4
4
|
Summary: Python SDK for calling the ProxyML API
|
|
5
5
|
Author-email: ProxyML <contact@proxyml.ai>
|
|
6
6
|
License: Apache License
|
|
@@ -209,7 +209,7 @@ Requires-Dist: requests>=2.28
|
|
|
209
209
|
Requires-Dist: numpy>=1.23
|
|
210
210
|
Requires-Dist: pandas>=1.5
|
|
211
211
|
Requires-Dist: orjson>=3.9
|
|
212
|
-
Requires-Dist: proxyml-core>=0.1
|
|
212
|
+
Requires-Dist: proxyml-core>=0.1.0
|
|
213
213
|
Provides-Extra: local
|
|
214
214
|
Requires-Dist: proxyml-core[modeling]>=0.2.2; extra == "local"
|
|
215
215
|
Provides-Extra: dev
|
|
@@ -306,7 +306,7 @@ if cf is not None:
|
|
|
306
306
|
print(explanation)
|
|
307
307
|
```
|
|
308
308
|
|
|
309
|
-
See [`docs/quickstart.md`](docs/quickstart.md) for a full walkthrough and [`docs/api.md`](docs/api.md) for complete API reference.
|
|
309
|
+
See [`docs/challenger.md`](docs/challenger.md) for the end-to-end challenger flow (train, upload, CI, PR comments), [`docs/quickstart.md`](docs/quickstart.md) for a full walkthrough and [`docs/api.md`](docs/api.md) for complete API reference.
|
|
310
310
|
|
|
311
311
|
## Core Concepts
|
|
312
312
|
|
|
@@ -335,6 +335,8 @@ See [`docs/quickstart.md`](docs/quickstart.md) for a full walkthrough and [`docs
|
|
|
335
335
|
| `proxyml.local.train_auto_challenger(data, target_col, ...)` | Load data + train a local challenger in one call |
|
|
336
336
|
| `upload_challenger(payload, ci_token=None)` | Upload a challenger comparison headlessly, e.g. from CI (`PROXYML_CI_TOKEN`, not `PROXYML_API_KEY`) |
|
|
337
337
|
| `get_challenger_summary(ci_token=None)` | Fetch a CI-ready summary of the latest challenger comparison |
|
|
338
|
+
| `check_data_drift(model_id, df, ...)` | Compare recent data against a model's training data (statistics only leave your machine); returns a pass/drift verdict |
|
|
339
|
+
| `list_drift_checks(model_id)` / `get_drift_check(model_id, snapshot_id)` | Browse stored drift verdicts |
|
|
338
340
|
| `proxyml.ci.post_challenger_comment(...)` | Post/update a sticky PR comment with the challenger comparison |
|
|
339
341
|
|
|
340
342
|
Full documentation: [`docs/api.md`](docs/api.md)
|
|
@@ -84,7 +84,7 @@ if cf is not None:
|
|
|
84
84
|
print(explanation)
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
See [`docs/quickstart.md`](docs/quickstart.md) for a full walkthrough and [`docs/api.md`](docs/api.md) for complete API reference.
|
|
87
|
+
See [`docs/challenger.md`](docs/challenger.md) for the end-to-end challenger flow (train, upload, CI, PR comments), [`docs/quickstart.md`](docs/quickstart.md) for a full walkthrough and [`docs/api.md`](docs/api.md) for complete API reference.
|
|
88
88
|
|
|
89
89
|
## Core Concepts
|
|
90
90
|
|
|
@@ -113,6 +113,8 @@ See [`docs/quickstart.md`](docs/quickstart.md) for a full walkthrough and [`docs
|
|
|
113
113
|
| `proxyml.local.train_auto_challenger(data, target_col, ...)` | Load data + train a local challenger in one call |
|
|
114
114
|
| `upload_challenger(payload, ci_token=None)` | Upload a challenger comparison headlessly, e.g. from CI (`PROXYML_CI_TOKEN`, not `PROXYML_API_KEY`) |
|
|
115
115
|
| `get_challenger_summary(ci_token=None)` | Fetch a CI-ready summary of the latest challenger comparison |
|
|
116
|
+
| `check_data_drift(model_id, df, ...)` | Compare recent data against a model's training data (statistics only leave your machine); returns a pass/drift verdict |
|
|
117
|
+
| `list_drift_checks(model_id)` / `get_drift_check(model_id, snapshot_id)` | Browse stored drift verdicts |
|
|
116
118
|
| `proxyml.ci.post_challenger_comment(...)` | Post/update a sticky PR comment with the challenger comparison |
|
|
117
119
|
|
|
118
120
|
Full documentation: [`docs/api.md`](docs/api.md)
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "proxyml"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.11.0"
|
|
8
8
|
description = "Python SDK for calling the ProxyML API"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = {file = "LICENSE"}
|
|
@@ -30,7 +30,7 @@ dependencies = [
|
|
|
30
30
|
"numpy>=1.23",
|
|
31
31
|
"pandas>=1.5",
|
|
32
32
|
"orjson>=3.9",
|
|
33
|
-
"proxyml-core>=0.1",
|
|
33
|
+
"proxyml-core>=0.1.0",
|
|
34
34
|
]
|
|
35
35
|
|
|
36
36
|
[project.optional-dependencies]
|
|
@@ -28,6 +28,9 @@ from proxyml.client import (
|
|
|
28
28
|
update_model,
|
|
29
29
|
upload_challenger,
|
|
30
30
|
get_challenger_summary,
|
|
31
|
+
check_data_drift,
|
|
32
|
+
list_drift_checks,
|
|
33
|
+
get_drift_check,
|
|
31
34
|
)
|
|
32
35
|
from proxyml.schema_builder import get_schema
|
|
33
36
|
|
|
@@ -62,5 +65,8 @@ __all__ = [
|
|
|
62
65
|
"update_model",
|
|
63
66
|
"upload_challenger",
|
|
64
67
|
"get_challenger_summary",
|
|
68
|
+
"check_data_drift",
|
|
69
|
+
"list_drift_checks",
|
|
70
|
+
"get_drift_check",
|
|
65
71
|
"get_schema",
|
|
66
72
|
]
|
|
@@ -926,3 +926,102 @@ def get_challenger_summary(*, ci_token: str | None = None) -> dict | None:
|
|
|
926
926
|
r.text,
|
|
927
927
|
)
|
|
928
928
|
return None
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
def check_data_drift(
|
|
932
|
+
model_id: str,
|
|
933
|
+
df: pd.DataFrame | None = None,
|
|
934
|
+
*,
|
|
935
|
+
schema: FeatureSchema | None = None,
|
|
936
|
+
label: str | None = None,
|
|
937
|
+
thresholds: dict | None = None,
|
|
938
|
+
baseline_n_samples: int | None = None,
|
|
939
|
+
) -> dict | None:
|
|
940
|
+
"""
|
|
941
|
+
Compares a batch of recent data against the data a model was trained on and
|
|
942
|
+
returns a drift verdict.
|
|
943
|
+
|
|
944
|
+
Only summary statistics leave your machine (means, standard deviations,
|
|
945
|
+
category names with their frequencies, count rates) -- never rows. Each feature's marginal
|
|
946
|
+
distribution is compared with the model's stored schema; correlations
|
|
947
|
+
between features are not checked. The verdict is also stored (the last
|
|
948
|
+
100 per model are kept) -- see list_drift_checks().
|
|
949
|
+
|
|
950
|
+
Args:
|
|
951
|
+
model_id (str): the surrogate whose training schema is the baseline.
|
|
952
|
+
df (DataFrame): recent data, with the same columns as the training data.
|
|
953
|
+
Summarized with get_schema(), so column types are inferred from
|
|
954
|
+
dtypes; if the model's schema uses hand-tuned types (e.g. ordinal),
|
|
955
|
+
pass ``schema`` instead.
|
|
956
|
+
schema (FeatureSchema): pre-built summary of ``df`` that replaces the
|
|
957
|
+
inferred one. ``df`` is still required, for its row count.
|
|
958
|
+
label (str): free-text tag stored with the check, e.g. a date or commit.
|
|
959
|
+
thresholds (dict): overrides of the drift policy, any of mean_shift,
|
|
960
|
+
std_ratio, category_tvd, count_rel_change, new_category_mass,
|
|
961
|
+
noise_sigmas, min_samples. Omitted values use the server defaults.
|
|
962
|
+
baseline_n_samples (int): rows the training schema was computed from, if
|
|
963
|
+
you know it. Widens the sampling-noise allowance; strongly
|
|
964
|
+
recommended when the training set was small.
|
|
965
|
+
|
|
966
|
+
Returns:
|
|
967
|
+
dict with ``status`` ("pass", "drift" or "insufficient_sample"),
|
|
968
|
+
``passed``, ``summary`` counts and per-feature ``features`` findings,
|
|
969
|
+
or None if the request failed. Drift is a normal response, not an
|
|
970
|
+
error: check ``result["passed"]``.
|
|
971
|
+
"""
|
|
972
|
+
if df is None:
|
|
973
|
+
raise ValueError("df is required (its row count is the sample size, even if schema= is given)")
|
|
974
|
+
if len(df) == 0:
|
|
975
|
+
raise ValueError("df has no rows")
|
|
976
|
+
summary = schema if schema is not None else get_schema(df)
|
|
977
|
+
payload: dict = {"n_samples": int(len(df)), "features": summary.to_dict()["features"]}
|
|
978
|
+
if label is not None:
|
|
979
|
+
payload["label"] = label
|
|
980
|
+
if thresholds:
|
|
981
|
+
payload["thresholds"] = thresholds
|
|
982
|
+
if baseline_n_samples is not None:
|
|
983
|
+
payload["baseline_n_samples"] = baseline_n_samples
|
|
984
|
+
r = post(endpoint=f'/surrogate/{model_id}/data-drift', payload=payload)
|
|
985
|
+
if r.status_code == 200:
|
|
986
|
+
result = r.json()
|
|
987
|
+
if result.get("summary", {}).get("type_changed"):
|
|
988
|
+
logger.warning(
|
|
989
|
+
"Some features changed type versus the model's schema. If the schema uses "
|
|
990
|
+
"hand-tuned types (e.g. ordinal), build the summary yourself and pass schema=."
|
|
991
|
+
)
|
|
992
|
+
return result
|
|
993
|
+
logger.error(
|
|
994
|
+
"Data drift check failed with status %s: %s",
|
|
995
|
+
r.status_code,
|
|
996
|
+
r.text,
|
|
997
|
+
)
|
|
998
|
+
return None
|
|
999
|
+
|
|
1000
|
+
|
|
1001
|
+
def list_drift_checks(model_id: str, limit: int = 20) -> dict | None:
|
|
1002
|
+
"""
|
|
1003
|
+
Lists a model's recent data drift verdicts, newest first (the last 100 are kept).
|
|
1004
|
+
|
|
1005
|
+
Returns:
|
|
1006
|
+
dict with ``snapshots`` (id, created_at, label, status, passed, n_samples,
|
|
1007
|
+
summary), or None if an error occurred.
|
|
1008
|
+
"""
|
|
1009
|
+
r = get(endpoint=f'/surrogate/{model_id}/data-drift', params={'limit': limit})
|
|
1010
|
+
if r.status_code == 200:
|
|
1011
|
+
return r.json()
|
|
1012
|
+
logger.error("Listing drift checks failed with status %s: %s", r.status_code, r.text)
|
|
1013
|
+
return None
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
def get_drift_check(model_id: str, snapshot_id: str) -> dict | None:
|
|
1017
|
+
"""
|
|
1018
|
+
Fetches one stored drift verdict, including its per-feature findings.
|
|
1019
|
+
|
|
1020
|
+
Returns:
|
|
1021
|
+
The same dict check_data_drift() returned, or None if an error occurred.
|
|
1022
|
+
"""
|
|
1023
|
+
r = get(endpoint=f'/surrogate/{model_id}/data-drift/{snapshot_id}')
|
|
1024
|
+
if r.status_code == 200:
|
|
1025
|
+
return r.json()
|
|
1026
|
+
logger.error("Fetching drift check failed with status %s: %s", r.status_code, r.text)
|
|
1027
|
+
return None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: proxyml
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0
|
|
4
4
|
Summary: Python SDK for calling the ProxyML API
|
|
5
5
|
Author-email: ProxyML <contact@proxyml.ai>
|
|
6
6
|
License: Apache License
|
|
@@ -209,7 +209,7 @@ Requires-Dist: requests>=2.28
|
|
|
209
209
|
Requires-Dist: numpy>=1.23
|
|
210
210
|
Requires-Dist: pandas>=1.5
|
|
211
211
|
Requires-Dist: orjson>=3.9
|
|
212
|
-
Requires-Dist: proxyml-core>=0.1
|
|
212
|
+
Requires-Dist: proxyml-core>=0.1.0
|
|
213
213
|
Provides-Extra: local
|
|
214
214
|
Requires-Dist: proxyml-core[modeling]>=0.2.2; extra == "local"
|
|
215
215
|
Provides-Extra: dev
|
|
@@ -306,7 +306,7 @@ if cf is not None:
|
|
|
306
306
|
print(explanation)
|
|
307
307
|
```
|
|
308
308
|
|
|
309
|
-
See [`docs/quickstart.md`](docs/quickstart.md) for a full walkthrough and [`docs/api.md`](docs/api.md) for complete API reference.
|
|
309
|
+
See [`docs/challenger.md`](docs/challenger.md) for the end-to-end challenger flow (train, upload, CI, PR comments), [`docs/quickstart.md`](docs/quickstart.md) for a full walkthrough and [`docs/api.md`](docs/api.md) for complete API reference.
|
|
310
310
|
|
|
311
311
|
## Core Concepts
|
|
312
312
|
|
|
@@ -335,6 +335,8 @@ See [`docs/quickstart.md`](docs/quickstart.md) for a full walkthrough and [`docs
|
|
|
335
335
|
| `proxyml.local.train_auto_challenger(data, target_col, ...)` | Load data + train a local challenger in one call |
|
|
336
336
|
| `upload_challenger(payload, ci_token=None)` | Upload a challenger comparison headlessly, e.g. from CI (`PROXYML_CI_TOKEN`, not `PROXYML_API_KEY`) |
|
|
337
337
|
| `get_challenger_summary(ci_token=None)` | Fetch a CI-ready summary of the latest challenger comparison |
|
|
338
|
+
| `check_data_drift(model_id, df, ...)` | Compare recent data against a model's training data (statistics only leave your machine); returns a pass/drift verdict |
|
|
339
|
+
| `list_drift_checks(model_id)` / `get_drift_check(model_id, snapshot_id)` | Browse stored drift verdicts |
|
|
338
340
|
| `proxyml.ci.post_challenger_comment(...)` | Post/update a sticky PR comment with the challenger comparison |
|
|
339
341
|
|
|
340
342
|
Full documentation: [`docs/api.md`](docs/api.md)
|
|
@@ -40,6 +40,9 @@ from proxyml.client import (
|
|
|
40
40
|
train_auto_surrogate,
|
|
41
41
|
update_model,
|
|
42
42
|
upload_challenger,
|
|
43
|
+
check_data_drift,
|
|
44
|
+
list_drift_checks,
|
|
45
|
+
get_drift_check,
|
|
43
46
|
)
|
|
44
47
|
|
|
45
48
|
|
|
@@ -1111,3 +1114,59 @@ def test_get_challenger_summary_failure_returns_none(mock_get, monkeypatch):
|
|
|
1111
1114
|
monkeypatch.setenv("PROXYML_CI_TOKEN", "test-ci-token")
|
|
1112
1115
|
mock_get.return_value = _mock_response(404, {"detail": "no challenger uploaded"})
|
|
1113
1116
|
assert get_challenger_summary() is None
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
# ---------------------------------------------------------------------------
|
|
1120
|
+
# data drift
|
|
1121
|
+
# ---------------------------------------------------------------------------
|
|
1122
|
+
|
|
1123
|
+
@patch("proxyml.client.post")
|
|
1124
|
+
def test_check_data_drift_sends_summary_not_rows(mock_post):
|
|
1125
|
+
verdict = {"status": "pass", "passed": True, "summary": {"drifted": 0}, "features": []}
|
|
1126
|
+
mock_post.return_value = _mock_response(200, verdict)
|
|
1127
|
+
df = pd.DataFrame({"a": [1.0, 2.0, 3.0], "b": ["x", "y", "x"]})
|
|
1128
|
+
|
|
1129
|
+
result = check_data_drift("m1", df, label="nightly", thresholds={"mean_shift": 0.5}, baseline_n_samples=900)
|
|
1130
|
+
|
|
1131
|
+
assert result == verdict
|
|
1132
|
+
kwargs = mock_post.call_args.kwargs
|
|
1133
|
+
assert kwargs["endpoint"] == "/surrogate/m1/data-drift"
|
|
1134
|
+
payload = kwargs["payload"]
|
|
1135
|
+
assert payload["n_samples"] == 3
|
|
1136
|
+
assert [f["name"] for f in payload["features"]] == ["a", "b"]
|
|
1137
|
+
assert payload["label"] == "nightly"
|
|
1138
|
+
assert payload["thresholds"] == {"mean_shift": 0.5}
|
|
1139
|
+
assert payload["baseline_n_samples"] == 900
|
|
1140
|
+
assert "covariance_matrix" not in payload
|
|
1141
|
+
assert set(payload["features"][0]) <= {"name", "type", "immutable", "mean", "std", "min", "max"} # statistics only
|
|
1142
|
+
|
|
1143
|
+
|
|
1144
|
+
@patch("proxyml.client.post")
|
|
1145
|
+
def test_check_data_drift_omits_optional_fields(mock_post):
|
|
1146
|
+
mock_post.return_value = _mock_response(200, {"status": "pass", "summary": {}})
|
|
1147
|
+
check_data_drift("m1", pd.DataFrame({"a": [1.0, 2.0]}))
|
|
1148
|
+
assert set(mock_post.call_args.kwargs["payload"]) == {"n_samples", "features"}
|
|
1149
|
+
|
|
1150
|
+
|
|
1151
|
+
@patch("proxyml.client.post")
|
|
1152
|
+
def test_check_data_drift_failure_returns_none(mock_post):
|
|
1153
|
+
mock_post.return_value = _mock_response(404, {"detail": "Model not found"})
|
|
1154
|
+
assert check_data_drift("nope", pd.DataFrame({"a": [1.0]})) is None
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
def test_check_data_drift_requires_rows():
|
|
1158
|
+
with pytest.raises(ValueError):
|
|
1159
|
+
check_data_drift("m1", None)
|
|
1160
|
+
with pytest.raises(ValueError):
|
|
1161
|
+
check_data_drift("m1", pd.DataFrame({"a": []}))
|
|
1162
|
+
|
|
1163
|
+
|
|
1164
|
+
@patch("proxyml.client.get")
|
|
1165
|
+
def test_list_and_get_drift_checks(mock_get):
|
|
1166
|
+
mock_get.return_value = _mock_response(200, {"snapshots": []})
|
|
1167
|
+
assert list_drift_checks("m1", limit=5) == {"snapshots": []}
|
|
1168
|
+
mock_get.assert_called_with(endpoint="/surrogate/m1/data-drift", params={"limit": 5})
|
|
1169
|
+
mock_get.return_value = _mock_response(200, {"snapshot_id": "s1"})
|
|
1170
|
+
assert get_drift_check("m1", "s1") == {"snapshot_id": "s1"}
|
|
1171
|
+
mock_get.return_value = _mock_response(404, {})
|
|
1172
|
+
assert get_drift_check("m1", "zz") is None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|