ectype-data 0.1.0__py3-none-any.whl
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.
- ectype/__init__.py +134 -0
- ectype/_version.py +5 -0
- ectype/authoring/__init__.py +13 -0
- ectype/authoring/builder.py +134 -0
- ectype/authoring/spec.py +555 -0
- ectype/calibration/__init__.py +26 -0
- ectype/calibration/adjustments.py +539 -0
- ectype/calibration/calibrator.py +781 -0
- ectype/cli.py +1181 -0
- ectype/compiler/__init__.py +1 -0
- ectype/compiler/plan.py +678 -0
- ectype/errors.py +43 -0
- ectype/fingerprint/__init__.py +1 -0
- ectype/fingerprint/comparison.py +746 -0
- ectype/fingerprint/container.py +408 -0
- ectype/fingerprint/core.py +263 -0
- ectype/fingerprint/disclosure.py +207 -0
- ectype/fingerprint/expressions.py +1317 -0
- ectype/fingerprint/schema.py +645 -0
- ectype/fingerprint/targets.py +352 -0
- ectype/generation/__init__.py +1 -0
- ectype/generation/enforce.py +163 -0
- ectype/generation/generator.py +525 -0
- ectype/generation/identifiers.py +235 -0
- ectype/generation/manifest.py +71 -0
- ectype/generation/parallel.py +229 -0
- ectype/io/__init__.py +16 -0
- ectype/io/adapters.py +224 -0
- ectype/io/sql.py +289 -0
- ectype/io/values.py +269 -0
- ectype/llm/__init__.py +27 -0
- ectype/llm/authoring.py +766 -0
- ectype/llm/providers.py +269 -0
- ectype/models/__init__.py +8 -0
- ectype/models/base.py +120 -0
- ectype/models/chain.py +2426 -0
- ectype/models/copulas.py +254 -0
- ectype/models/encoding.py +1117 -0
- ectype/models/forest.py +1087 -0
- ectype/models/marginals.py +2099 -0
- ectype/models/mixtures.py +336 -0
- ectype/models/neural/__init__.py +21 -0
- ectype/models/neural/adapter.py +638 -0
- ectype/models/neural/vae.py +432 -0
- ectype/models/vines.py +608 -0
- ectype/plugins.py +40 -0
- ectype/privacy/__init__.py +49 -0
- ectype/privacy/attacks.py +599 -0
- ectype/privacy/dp.py +313 -0
- ectype/privacy/report.py +364 -0
- ectype/profiler.py +783 -0
- ectype/profiling/__init__.py +1 -0
- ectype/profiling/bivariate.py +130 -0
- ectype/profiling/calendar.py +743 -0
- ectype/profiling/conditional.py +263 -0
- ectype/profiling/constraints.py +661 -0
- ectype/profiling/entity.py +1143 -0
- ectype/profiling/functional.py +651 -0
- ectype/profiling/multivariate.py +492 -0
- ectype/profiling/personal.py +277 -0
- ectype/profiling/pseudonym.py +370 -0
- ectype/profiling/reference.py +334 -0
- ectype/profiling/sketches.py +653 -0
- ectype/profiling/structural.py +1087 -0
- ectype/profiling/structure.py +1733 -0
- ectype/profiling/sums.py +1710 -0
- ectype/profiling/tolerance.py +435 -0
- ectype/profiling/univariate.py +555 -0
- ectype/py.typed +0 -0
- ectype/registry.py +48 -0
- ectype/relational/__init__.py +61 -0
- ectype/relational/container.py +212 -0
- ectype/relational/fit.py +633 -0
- ectype/relational/generate.py +418 -0
- ectype/relational/schema.py +280 -0
- ectype/relational/validate.py +288 -0
- ectype/reporting/__init__.py +439 -0
- ectype/reporting/adapter.py +2003 -0
- ectype/reporting/charts.py +964 -0
- ectype/reporting/drift.py +902 -0
- ectype/reporting/findings.py +622 -0
- ectype/reporting/fmt.py +429 -0
- ectype/reporting/render.py +1705 -0
- ectype/reporting/select.py +84 -0
- ectype/reporting/style.py +272 -0
- ectype/reporting/view.py +593 -0
- ectype/rng.py +33 -0
- ectype/scenarios/__init__.py +30 -0
- ectype/scenarios/feasibility.py +411 -0
- ectype/scenarios/merge.py +1392 -0
- ectype/scenarios/mutate.py +1613 -0
- ectype/temporal/__init__.py +80 -0
- ectype/temporal/contract.py +221 -0
- ectype/temporal/detect.py +431 -0
- ectype/temporal/events.py +946 -0
- ectype/temporal/panel.py +937 -0
- ectype/temporal/pipeline.py +192 -0
- ectype/temporal/regular.py +674 -0
- ectype/types.py +46 -0
- ectype/validation/__init__.py +1 -0
- ectype/validation/metrics/__init__.py +7 -0
- ectype/validation/metrics/base.py +68 -0
- ectype/validation/metrics/bivariate.py +353 -0
- ectype/validation/metrics/missingness.py +54 -0
- ectype/validation/metrics/multivariate.py +265 -0
- ectype/validation/metrics/temporal.py +596 -0
- ectype/validation/metrics/univariate.py +514 -0
- ectype/validation/report.py +627 -0
- ectype/validation/validator.py +707 -0
- ectype_data-0.1.0.dist-info/METADATA +376 -0
- ectype_data-0.1.0.dist-info/RECORD +115 -0
- ectype_data-0.1.0.dist-info/WHEEL +4 -0
- ectype_data-0.1.0.dist-info/entry_points.txt +2 -0
- ectype_data-0.1.0.dist-info/licenses/LICENSE +192 -0
- ectype_data-0.1.0.dist-info/licenses/NOTICE +5 -0
ectype/__init__.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""ectype: statistical fingerprinting, reconstruction and simulation for tables.
|
|
2
|
+
|
|
3
|
+
Typical use::
|
|
4
|
+
|
|
5
|
+
import ectype
|
|
6
|
+
|
|
7
|
+
fp = ectype.fit(df) # learn a fingerprint
|
|
8
|
+
fp.save("data.dfp") # portable, declarative artifact
|
|
9
|
+
|
|
10
|
+
gen = ectype.Generator.from_fingerprint("data.dfp") # no source data needed
|
|
11
|
+
synthetic = gen.generate(100_000, seed=42)
|
|
12
|
+
|
|
13
|
+
report = ectype.validate(fp, synthetic, holdout=real_holdout)
|
|
14
|
+
print(report.summary())
|
|
15
|
+
|
|
16
|
+
drift = ectype.compare(ectype.load("jan.dfp"), ectype.load("feb.dfp"))
|
|
17
|
+
ectype.report("data.dfp").to_html("data-report.html") # one-page profile report
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
from typing import TYPE_CHECKING, Any
|
|
23
|
+
|
|
24
|
+
from ectype._version import FORMAT_VERSION, __version__
|
|
25
|
+
from ectype.errors import (
|
|
26
|
+
ConstraintError,
|
|
27
|
+
EctypeError,
|
|
28
|
+
ExpressionError,
|
|
29
|
+
FingerprintError,
|
|
30
|
+
GenerationError,
|
|
31
|
+
IntegrityError,
|
|
32
|
+
PolicyError,
|
|
33
|
+
ProfilingError,
|
|
34
|
+
ScenarioError,
|
|
35
|
+
VersionError,
|
|
36
|
+
)
|
|
37
|
+
from ectype.fingerprint.core import Fingerprint
|
|
38
|
+
|
|
39
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
40
|
+
from ectype.fingerprint.comparison import DriftReport, compare
|
|
41
|
+
from ectype.generation.generator import Generator
|
|
42
|
+
from ectype.profiler import Profiler, fit
|
|
43
|
+
from ectype.reporting import ProfileReport, report
|
|
44
|
+
from ectype.validation.report import ValidationReport
|
|
45
|
+
from ectype.validation.validator import validate
|
|
46
|
+
|
|
47
|
+
_LAZY = {
|
|
48
|
+
"Profiler": ("ectype.profiler", "Profiler"),
|
|
49
|
+
"fit": ("ectype.profiler", "fit"),
|
|
50
|
+
"Generator": ("ectype.generation.generator", "Generator"),
|
|
51
|
+
"validate": ("ectype.validation.validator", "validate"),
|
|
52
|
+
"ValidationReport": ("ectype.validation.report", "ValidationReport"),
|
|
53
|
+
"compare": ("ectype.fingerprint.comparison", "compare"),
|
|
54
|
+
"DriftReport": ("ectype.fingerprint.comparison", "DriftReport"),
|
|
55
|
+
"manifest_json_schema": ("ectype.fingerprint.schema", "manifest_json_schema"),
|
|
56
|
+
"read_table": ("ectype.io", "read_table"),
|
|
57
|
+
"RelationalSchema": ("ectype.relational", "RelationalSchema"),
|
|
58
|
+
"Relationship": ("ectype.relational", "Relationship"),
|
|
59
|
+
"RelationalProfiler": ("ectype.relational", "RelationalProfiler"),
|
|
60
|
+
"RelationalGenerator": ("ectype.relational", "RelationalGenerator"),
|
|
61
|
+
"RelationalFingerprint": ("ectype.relational", "RelationalFingerprint"),
|
|
62
|
+
"validate_relational": ("ectype.relational", "validate_relational"),
|
|
63
|
+
"calibrate": ("ectype.calibration", "calibrate"),
|
|
64
|
+
"mutate": ("ectype.scenarios", "mutate"),
|
|
65
|
+
"merge": ("ectype.scenarios", "merge"),
|
|
66
|
+
"FingerprintBuilder": ("ectype.authoring", "FingerprintBuilder"),
|
|
67
|
+
"generate_temporal": ("ectype.temporal.pipeline", "generate_temporal"),
|
|
68
|
+
"validate_temporal": ("ectype.temporal.pipeline", "validate_temporal"),
|
|
69
|
+
"run_privacy_suite": ("ectype.privacy", "run_privacy_suite"),
|
|
70
|
+
"write_table": ("ectype.io", "write_table"),
|
|
71
|
+
"report": ("ectype.reporting", "report"),
|
|
72
|
+
"ProfileReport": ("ectype.reporting", "ProfileReport"),
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def __getattr__(name: str) -> Any:
|
|
77
|
+
"""Lazy imports keep ``import ectype`` fast and side-effect free."""
|
|
78
|
+
try:
|
|
79
|
+
module, attr = _LAZY[name]
|
|
80
|
+
except KeyError:
|
|
81
|
+
raise AttributeError(f"module 'ectype' has no attribute {name!r}") from None
|
|
82
|
+
import importlib
|
|
83
|
+
|
|
84
|
+
value = getattr(importlib.import_module(module), attr)
|
|
85
|
+
globals()[name] = value
|
|
86
|
+
return value
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def load(path: str) -> Fingerprint:
|
|
90
|
+
"""Load and fully validate a ``.dfp`` fingerprint."""
|
|
91
|
+
return Fingerprint.load(path)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
__all__ = [
|
|
95
|
+
"FORMAT_VERSION",
|
|
96
|
+
"FingerprintBuilder",
|
|
97
|
+
"RelationalFingerprint",
|
|
98
|
+
"RelationalGenerator",
|
|
99
|
+
"RelationalProfiler",
|
|
100
|
+
"RelationalSchema",
|
|
101
|
+
"Relationship",
|
|
102
|
+
"calibrate",
|
|
103
|
+
"generate_temporal",
|
|
104
|
+
"merge",
|
|
105
|
+
"mutate",
|
|
106
|
+
"run_privacy_suite",
|
|
107
|
+
"validate_relational",
|
|
108
|
+
"validate_temporal",
|
|
109
|
+
"ConstraintError",
|
|
110
|
+
"DriftReport",
|
|
111
|
+
"ExpressionError",
|
|
112
|
+
"Fingerprint",
|
|
113
|
+
"FingerprintError",
|
|
114
|
+
"GenerationError",
|
|
115
|
+
"Generator",
|
|
116
|
+
"IntegrityError",
|
|
117
|
+
"PolicyError",
|
|
118
|
+
"ProfileReport",
|
|
119
|
+
"Profiler",
|
|
120
|
+
"ProfilingError",
|
|
121
|
+
"ScenarioError",
|
|
122
|
+
"EctypeError",
|
|
123
|
+
"ValidationReport",
|
|
124
|
+
"VersionError",
|
|
125
|
+
"__version__",
|
|
126
|
+
"compare",
|
|
127
|
+
"fit",
|
|
128
|
+
"load",
|
|
129
|
+
"manifest_json_schema",
|
|
130
|
+
"read_table",
|
|
131
|
+
"report",
|
|
132
|
+
"validate",
|
|
133
|
+
"write_table",
|
|
134
|
+
]
|
ectype/_version.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Schema-driven authoring (M27): build fingerprints from stated distributions, relationships
|
|
2
|
+
and rules, with no source data."""
|
|
3
|
+
|
|
4
|
+
from ectype.authoring.builder import FingerprintBuilder
|
|
5
|
+
from ectype.authoring.spec import (
|
|
6
|
+
AuthoringError,
|
|
7
|
+
build_from_spec,
|
|
8
|
+
compile_spec,
|
|
9
|
+
normalize_spec,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = ["AuthoringError", "FingerprintBuilder", "build_from_spec", "compile_spec",
|
|
13
|
+
"normalize_spec"]
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""Fluent Python builder for schema-driven fingerprints (M27).
|
|
2
|
+
|
|
3
|
+
::
|
|
4
|
+
|
|
5
|
+
fp = (FingerprintBuilder("customers")
|
|
6
|
+
.numeric("income", dist="lognormal", mu=10.5, sigma=0.6)
|
|
7
|
+
.numeric("age", dist="normal", mean=41, sd=12)
|
|
8
|
+
.categorical("segment", probs={"a": 0.5, "b": 0.3, "c": 0.2})
|
|
9
|
+
.boolean("vip", p=0.1)
|
|
10
|
+
.datetime("joined", "2020-01-01", "2024-12-31")
|
|
11
|
+
.correlation("income", "age", 0.4)
|
|
12
|
+
.constraint("age >= 18")
|
|
13
|
+
.derived("income_k", "income / 1000")
|
|
14
|
+
.missing("income", 0.05)
|
|
15
|
+
.build(policy="standard", n_reference=10_000, seed=0))
|
|
16
|
+
|
|
17
|
+
The builder only records a declarative spec (:meth:`to_spec`); :meth:`build` compiles it with
|
|
18
|
+
:func:`ectype.authoring.spec.compile_spec`, so ``build_from_spec(b.to_spec())`` gives
|
|
19
|
+
the same fingerprint. See that module for the semantics (correlations are Spearman by default).
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import copy
|
|
25
|
+
import datetime as dt
|
|
26
|
+
from typing import Any
|
|
27
|
+
|
|
28
|
+
from ectype.authoring.spec import (
|
|
29
|
+
DEFAULT_N_REFERENCE,
|
|
30
|
+
AuthoringError,
|
|
31
|
+
compile_spec,
|
|
32
|
+
normalize_spec,
|
|
33
|
+
)
|
|
34
|
+
from ectype.fingerprint.core import Fingerprint
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _when(x: Any) -> Any:
|
|
38
|
+
return x.isoformat() if isinstance(x, dt.date | dt.datetime) else x
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class FingerprintBuilder:
|
|
42
|
+
"""Accumulates columns, relationships and rules; ``build()`` returns a Fingerprint."""
|
|
43
|
+
|
|
44
|
+
def __init__(self, name: str = "authored", *, description: str | None = None) -> None:
|
|
45
|
+
self._spec: dict[str, Any] = {"name": str(name), "columns": [], "correlations": [],
|
|
46
|
+
"constraints": [], "derived": [], "missing": {}}
|
|
47
|
+
if description:
|
|
48
|
+
self._spec["description"] = description
|
|
49
|
+
|
|
50
|
+
# -- columns -------------------------------------------------------------------------------
|
|
51
|
+
def _add(self, entry: dict[str, Any]) -> FingerprintBuilder:
|
|
52
|
+
if any(c["name"] == entry["name"] for c in self._spec["columns"]):
|
|
53
|
+
raise AuthoringError(f"column {entry['name']!r} is declared twice")
|
|
54
|
+
self._spec["columns"].append(entry)
|
|
55
|
+
normalize_spec(self._spec) # validate eagerly: errors point at the call
|
|
56
|
+
return self
|
|
57
|
+
|
|
58
|
+
def numeric(self, col: str, dist: str = "lognormal", *, decimals: int | None = None,
|
|
59
|
+
dtype: str | None = None, **params: float) -> FingerprintBuilder:
|
|
60
|
+
entry: dict[str, Any] = {"name": col, "type": "numeric", "dist": dist,
|
|
61
|
+
"params": dict(params)}
|
|
62
|
+
if decimals is not None:
|
|
63
|
+
entry["decimals"] = decimals
|
|
64
|
+
if dtype is not None:
|
|
65
|
+
entry["dtype"] = dtype
|
|
66
|
+
return self._add(entry)
|
|
67
|
+
|
|
68
|
+
def categorical(self, col: str, probs: dict[Any, float]) -> FingerprintBuilder:
|
|
69
|
+
return self._add({"name": col, "type": "categorical",
|
|
70
|
+
"probs": {str(k): v for k, v in probs.items()}})
|
|
71
|
+
|
|
72
|
+
def boolean(self, col: str, p: float) -> FingerprintBuilder:
|
|
73
|
+
return self._add({"name": col, "type": "boolean", "p": p})
|
|
74
|
+
|
|
75
|
+
def datetime(self, col: str, start: Any, end: Any) -> FingerprintBuilder:
|
|
76
|
+
return self._add({"name": col, "type": "datetime", "start": _when(start),
|
|
77
|
+
"end": _when(end)})
|
|
78
|
+
|
|
79
|
+
def identifier(self, col: str, kind: str = "int_sequence", *,
|
|
80
|
+
start: int = 1) -> FingerprintBuilder:
|
|
81
|
+
entry: dict[str, Any] = {"name": col, "type": "identifier", "kind": kind}
|
|
82
|
+
if kind == "int_sequence":
|
|
83
|
+
entry["start_value"] = int(start)
|
|
84
|
+
return self._add(entry)
|
|
85
|
+
|
|
86
|
+
# -- relationships and rules -----------------------------------------------------------------
|
|
87
|
+
def correlation(self, a: str, b: str, rho: float, *,
|
|
88
|
+
method: str = "spearman") -> FingerprintBuilder:
|
|
89
|
+
self._spec["correlations"].append({"columns": [a, b], "rho": rho, "method": method})
|
|
90
|
+
try:
|
|
91
|
+
normalize_spec(self._spec)
|
|
92
|
+
except AuthoringError:
|
|
93
|
+
self._spec["correlations"].pop()
|
|
94
|
+
raise
|
|
95
|
+
return self
|
|
96
|
+
|
|
97
|
+
def constraint(self, expr: str, *, id: str | None = None) -> FingerprintBuilder: # noqa: A002
|
|
98
|
+
entry: dict[str, Any] = {"expression": expr}
|
|
99
|
+
entry["id"] = id or f"user_{len(self._spec['constraints']) + 1}"
|
|
100
|
+
self._spec["constraints"].append(entry)
|
|
101
|
+
return self
|
|
102
|
+
|
|
103
|
+
def derived(self, col: str, expr: str, *, dtype: str = "Float64",
|
|
104
|
+
logical_type: str = "continuous") -> FingerprintBuilder:
|
|
105
|
+
self._spec["derived"].append({"column": col, "expression": expr, "dtype": dtype,
|
|
106
|
+
"logical_type": logical_type})
|
|
107
|
+
try:
|
|
108
|
+
normalize_spec(self._spec)
|
|
109
|
+
except AuthoringError:
|
|
110
|
+
self._spec["derived"].pop()
|
|
111
|
+
raise
|
|
112
|
+
return self
|
|
113
|
+
|
|
114
|
+
def missing(self, col: str, rate: float) -> FingerprintBuilder:
|
|
115
|
+
self._spec["missing"][col] = rate
|
|
116
|
+
try:
|
|
117
|
+
normalize_spec(self._spec)
|
|
118
|
+
except AuthoringError:
|
|
119
|
+
del self._spec["missing"][col]
|
|
120
|
+
raise
|
|
121
|
+
return self
|
|
122
|
+
|
|
123
|
+
# -- output ------------------------------------------------------------------------------
|
|
124
|
+
def to_spec(self) -> dict[str, Any]:
|
|
125
|
+
"""The declarative spec (a plain dict, accepted by ``build_from_spec``)."""
|
|
126
|
+
return copy.deepcopy(self._spec)
|
|
127
|
+
|
|
128
|
+
def build(self, policy: Any = "standard", n_reference: int = DEFAULT_N_REFERENCE,
|
|
129
|
+
seed: int = 0, *, sealed_fraction: float = 0.3) -> Fingerprint:
|
|
130
|
+
return compile_spec(self._spec, policy=policy, n_reference=n_reference, seed=seed,
|
|
131
|
+
sealed_fraction=sealed_fraction)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
__all__ = ["FingerprintBuilder"]
|