proxyml-core 0.2.0__tar.gz → 0.2.2__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_core-0.2.0 → proxyml_core-0.2.2}/PKG-INFO +1 -1
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/pyproject.toml +1 -1
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/src/proxyml_core/__init__.py +3 -0
- proxyml_core-0.2.2/src/proxyml_core/fingerprint.py +34 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/src/proxyml_core/modeling/estimators.py +5 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/src/proxyml_core.egg-info/PKG-INFO +1 -1
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/src/proxyml_core.egg-info/SOURCES.txt +2 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/tests/test_dependency_boundaries.py +1 -1
- proxyml_core-0.2.2/tests/test_fingerprint.py +21 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/tests/test_modeling_estimators.py +26 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/LICENSE +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/README.md +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/setup.cfg +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/src/proxyml_core/_version.py +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/src/proxyml_core/export.py +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/src/proxyml_core/modeling/__init__.py +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/src/proxyml_core/modeling/extract.py +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/src/proxyml_core/modeling/preprocess.py +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/src/proxyml_core/modeling/scoring.py +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/src/proxyml_core/schema.py +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/src/proxyml_core.egg-info/dependency_links.txt +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/src/proxyml_core.egg-info/requires.txt +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/src/proxyml_core.egg-info/top_level.txt +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/tests/test_export.py +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/tests/test_export_version_contract.py +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/tests/test_modeling_extract.py +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/tests/test_modeling_preprocess.py +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/tests/test_modeling_scoring.py +0 -0
- {proxyml_core-0.2.0 → proxyml_core-0.2.2}/tests/test_schema.py +0 -0
|
@@ -15,6 +15,7 @@ from proxyml_core.export import (
|
|
|
15
15
|
predict_from_export,
|
|
16
16
|
score_export,
|
|
17
17
|
)
|
|
18
|
+
from proxyml_core.fingerprint import FINGERPRINT_MISMATCH_MESSAGE, check_fingerprints
|
|
18
19
|
from proxyml_core.schema import (
|
|
19
20
|
CategoricalFeature,
|
|
20
21
|
CategoricalOrdinalFeature,
|
|
@@ -49,4 +50,6 @@ __all__ = [
|
|
|
49
50
|
"EXPORT_SCHEMA_VERSION",
|
|
50
51
|
"IncompatibleExportVersionError",
|
|
51
52
|
"check_compatible",
|
|
53
|
+
"check_fingerprints",
|
|
54
|
+
"FINGERPRINT_MISMATCH_MESSAGE",
|
|
52
55
|
]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Shared data-population identity check.
|
|
2
|
+
|
|
3
|
+
``fingerprint_labels()`` (in the ``proxyml`` SDK's local-training module)
|
|
4
|
+
hashes a label array without the data ever leaving the caller's process;
|
|
5
|
+
what travels instead is the resulting fingerprint string. ``check_fingerprints``
|
|
6
|
+
is the other half of that contract: comparing two such fingerprints to
|
|
7
|
+
confirm a challenger and champion were actually scored on the same
|
|
8
|
+
population. It's pure (stdlib only) so the exact same check can run
|
|
9
|
+
client-side, in the SDK, before upload, and server-side, both to reject a
|
|
10
|
+
mismatched upload and to render a comparison's match status — one
|
|
11
|
+
implementation, not three that can quietly drift apart.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
FINGERPRINT_MISMATCH_MESSAGE = (
|
|
17
|
+
"challenger_data_fingerprint and champion_data_fingerprint don't match — "
|
|
18
|
+
"were the challenger and champion scored on the same data? "
|
|
19
|
+
"(e.g. train_challenger() and score_champion() called against different files)"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def check_fingerprints(challenger_fingerprint: str | None, champion_fingerprint: str | None) -> bool | None:
|
|
24
|
+
"""Whether two data fingerprints match, or ``None`` if either is missing.
|
|
25
|
+
|
|
26
|
+
Returns ``None`` — not ``False`` — when either fingerprint is absent,
|
|
27
|
+
since "unknown" and "confirmed mismatch" call for different handling:
|
|
28
|
+
a hard-validation caller should treat ``None`` as nothing to check yet,
|
|
29
|
+
while a caller rendering a status badge should show a neutral/unknown
|
|
30
|
+
state rather than a false-alarm red one.
|
|
31
|
+
"""
|
|
32
|
+
if challenger_fingerprint is None or champion_fingerprint is None:
|
|
33
|
+
return None
|
|
34
|
+
return challenger_fingerprint == champion_fingerprint
|
|
@@ -47,6 +47,10 @@ def binarize_if_probabilities(predictions: np.ndarray) -> np.ndarray:
|
|
|
47
47
|
if predictions.dtype.kind not in "iuf": # not int/uint/float — already discrete labels
|
|
48
48
|
return predictions
|
|
49
49
|
as_float = predictions.astype(float)
|
|
50
|
+
if not np.all(np.isfinite(as_float)):
|
|
51
|
+
# Casting NaN/inf to int is undefined — silently mis-binarizes to 0
|
|
52
|
+
# instead of raising, so reject it explicitly instead.
|
|
53
|
+
raise ValueError("predictions must not contain NaN or infinite values")
|
|
50
54
|
if np.all(as_float == as_float.astype(int)):
|
|
51
55
|
return predictions
|
|
52
56
|
return (as_float >= 0.5).astype(int)
|
|
@@ -60,6 +64,7 @@ def get_default_classifier() -> BaseEstimator:
|
|
|
60
64
|
max_iter=500,
|
|
61
65
|
cv=5,
|
|
62
66
|
n_jobs=-1,
|
|
67
|
+
scoring="accuracy",
|
|
63
68
|
use_legacy_attributes=False,
|
|
64
69
|
)
|
|
65
70
|
|
|
@@ -4,6 +4,7 @@ pyproject.toml
|
|
|
4
4
|
src/proxyml_core/__init__.py
|
|
5
5
|
src/proxyml_core/_version.py
|
|
6
6
|
src/proxyml_core/export.py
|
|
7
|
+
src/proxyml_core/fingerprint.py
|
|
7
8
|
src/proxyml_core/schema.py
|
|
8
9
|
src/proxyml_core.egg-info/PKG-INFO
|
|
9
10
|
src/proxyml_core.egg-info/SOURCES.txt
|
|
@@ -18,6 +19,7 @@ src/proxyml_core/modeling/scoring.py
|
|
|
18
19
|
tests/test_dependency_boundaries.py
|
|
19
20
|
tests/test_export.py
|
|
20
21
|
tests/test_export_version_contract.py
|
|
22
|
+
tests/test_fingerprint.py
|
|
21
23
|
tests/test_modeling_estimators.py
|
|
22
24
|
tests/test_modeling_extract.py
|
|
23
25
|
tests/test_modeling_preprocess.py
|
|
@@ -12,7 +12,7 @@ from pathlib import Path
|
|
|
12
12
|
|
|
13
13
|
import proxyml_core
|
|
14
14
|
|
|
15
|
-
_PURE_MODULES = ["schema.py", "export.py", "_version.py"]
|
|
15
|
+
_PURE_MODULES = ["schema.py", "export.py", "_version.py", "fingerprint.py"]
|
|
16
16
|
_ALLOWED_PURE_TOP_LEVEL = {"numpy"} | set(sys.stdlib_module_names)
|
|
17
17
|
_ALLOWED_MODELING_TOP_LEVEL = _ALLOWED_PURE_TOP_LEVEL | {"sklearn", "scipy"}
|
|
18
18
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from proxyml_core.fingerprint import check_fingerprints
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_check_fingerprints_match():
|
|
5
|
+
assert check_fingerprints("abc", "abc") is True
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_check_fingerprints_mismatch():
|
|
9
|
+
assert check_fingerprints("abc", "def") is False
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_check_fingerprints_missing_challenger():
|
|
13
|
+
assert check_fingerprints(None, "def") is None
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def test_check_fingerprints_missing_champion():
|
|
17
|
+
assert check_fingerprints("abc", None) is None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_check_fingerprints_both_missing():
|
|
21
|
+
assert check_fingerprints(None, None) is None
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
1
3
|
import numpy as np
|
|
4
|
+
import pytest
|
|
2
5
|
|
|
3
6
|
from proxyml_core.modeling.estimators import (
|
|
4
7
|
binarize_if_probabilities,
|
|
@@ -40,6 +43,18 @@ def test_binarize_if_probabilities_passes_through_object_labels():
|
|
|
40
43
|
assert list(out) == ["yes", "no"]
|
|
41
44
|
|
|
42
45
|
|
|
46
|
+
def test_binarize_if_probabilities_rejects_nan():
|
|
47
|
+
# Casting NaN to int is undefined and previously silently mis-binarized
|
|
48
|
+
# to 0 instead of raising — must fail loudly instead.
|
|
49
|
+
with pytest.raises(ValueError, match="NaN or infinite"):
|
|
50
|
+
binarize_if_probabilities(np.array([0.1, 0.6, np.nan, 0.5]))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_binarize_if_probabilities_rejects_inf():
|
|
54
|
+
with pytest.raises(ValueError, match="NaN or infinite"):
|
|
55
|
+
binarize_if_probabilities(np.array([0.1, 0.6, np.inf, 0.5]))
|
|
56
|
+
|
|
57
|
+
|
|
43
58
|
def test_to_json_safe_handles_numpy_types():
|
|
44
59
|
assert to_json_safe(np.array([1, 2, 3])) == [1, 2, 3]
|
|
45
60
|
assert to_json_safe(np.float64(1.5)) == 1.5
|
|
@@ -57,6 +72,17 @@ def test_extract_hyperparameters_includes_cv_selected_values():
|
|
|
57
72
|
assert isinstance(params["alpha_"], float)
|
|
58
73
|
|
|
59
74
|
|
|
75
|
+
def test_get_default_classifier_fits_without_sklearn_deprecation_warnings():
|
|
76
|
+
# scoring="accuracy" and use_legacy_attributes=False pin today's sklearn
|
|
77
|
+
# defaults explicitly, so upgrading sklearn can't silently change fit
|
|
78
|
+
# behavior and users don't see FutureWarning noise on every fit.
|
|
79
|
+
X = np.random.RandomState(0).normal(size=(50, 3))
|
|
80
|
+
y = (X[:, 0] > 0).astype(int)
|
|
81
|
+
with warnings.catch_warnings():
|
|
82
|
+
warnings.simplefilter("error", FutureWarning)
|
|
83
|
+
get_default_classifier().fit(X, y)
|
|
84
|
+
|
|
85
|
+
|
|
60
86
|
def test_get_default_classifier_and_regressor_are_fittable():
|
|
61
87
|
X = np.random.RandomState(0).normal(size=(50, 3))
|
|
62
88
|
y_class = (X[:, 0] > 0).astype(int)
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|