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.
Files changed (115) hide show
  1. ectype/__init__.py +134 -0
  2. ectype/_version.py +5 -0
  3. ectype/authoring/__init__.py +13 -0
  4. ectype/authoring/builder.py +134 -0
  5. ectype/authoring/spec.py +555 -0
  6. ectype/calibration/__init__.py +26 -0
  7. ectype/calibration/adjustments.py +539 -0
  8. ectype/calibration/calibrator.py +781 -0
  9. ectype/cli.py +1181 -0
  10. ectype/compiler/__init__.py +1 -0
  11. ectype/compiler/plan.py +678 -0
  12. ectype/errors.py +43 -0
  13. ectype/fingerprint/__init__.py +1 -0
  14. ectype/fingerprint/comparison.py +746 -0
  15. ectype/fingerprint/container.py +408 -0
  16. ectype/fingerprint/core.py +263 -0
  17. ectype/fingerprint/disclosure.py +207 -0
  18. ectype/fingerprint/expressions.py +1317 -0
  19. ectype/fingerprint/schema.py +645 -0
  20. ectype/fingerprint/targets.py +352 -0
  21. ectype/generation/__init__.py +1 -0
  22. ectype/generation/enforce.py +163 -0
  23. ectype/generation/generator.py +525 -0
  24. ectype/generation/identifiers.py +235 -0
  25. ectype/generation/manifest.py +71 -0
  26. ectype/generation/parallel.py +229 -0
  27. ectype/io/__init__.py +16 -0
  28. ectype/io/adapters.py +224 -0
  29. ectype/io/sql.py +289 -0
  30. ectype/io/values.py +269 -0
  31. ectype/llm/__init__.py +27 -0
  32. ectype/llm/authoring.py +766 -0
  33. ectype/llm/providers.py +269 -0
  34. ectype/models/__init__.py +8 -0
  35. ectype/models/base.py +120 -0
  36. ectype/models/chain.py +2426 -0
  37. ectype/models/copulas.py +254 -0
  38. ectype/models/encoding.py +1117 -0
  39. ectype/models/forest.py +1087 -0
  40. ectype/models/marginals.py +2099 -0
  41. ectype/models/mixtures.py +336 -0
  42. ectype/models/neural/__init__.py +21 -0
  43. ectype/models/neural/adapter.py +638 -0
  44. ectype/models/neural/vae.py +432 -0
  45. ectype/models/vines.py +608 -0
  46. ectype/plugins.py +40 -0
  47. ectype/privacy/__init__.py +49 -0
  48. ectype/privacy/attacks.py +599 -0
  49. ectype/privacy/dp.py +313 -0
  50. ectype/privacy/report.py +364 -0
  51. ectype/profiler.py +783 -0
  52. ectype/profiling/__init__.py +1 -0
  53. ectype/profiling/bivariate.py +130 -0
  54. ectype/profiling/calendar.py +743 -0
  55. ectype/profiling/conditional.py +263 -0
  56. ectype/profiling/constraints.py +661 -0
  57. ectype/profiling/entity.py +1143 -0
  58. ectype/profiling/functional.py +651 -0
  59. ectype/profiling/multivariate.py +492 -0
  60. ectype/profiling/personal.py +277 -0
  61. ectype/profiling/pseudonym.py +370 -0
  62. ectype/profiling/reference.py +334 -0
  63. ectype/profiling/sketches.py +653 -0
  64. ectype/profiling/structural.py +1087 -0
  65. ectype/profiling/structure.py +1733 -0
  66. ectype/profiling/sums.py +1710 -0
  67. ectype/profiling/tolerance.py +435 -0
  68. ectype/profiling/univariate.py +555 -0
  69. ectype/py.typed +0 -0
  70. ectype/registry.py +48 -0
  71. ectype/relational/__init__.py +61 -0
  72. ectype/relational/container.py +212 -0
  73. ectype/relational/fit.py +633 -0
  74. ectype/relational/generate.py +418 -0
  75. ectype/relational/schema.py +280 -0
  76. ectype/relational/validate.py +288 -0
  77. ectype/reporting/__init__.py +439 -0
  78. ectype/reporting/adapter.py +2003 -0
  79. ectype/reporting/charts.py +964 -0
  80. ectype/reporting/drift.py +902 -0
  81. ectype/reporting/findings.py +622 -0
  82. ectype/reporting/fmt.py +429 -0
  83. ectype/reporting/render.py +1705 -0
  84. ectype/reporting/select.py +84 -0
  85. ectype/reporting/style.py +272 -0
  86. ectype/reporting/view.py +593 -0
  87. ectype/rng.py +33 -0
  88. ectype/scenarios/__init__.py +30 -0
  89. ectype/scenarios/feasibility.py +411 -0
  90. ectype/scenarios/merge.py +1392 -0
  91. ectype/scenarios/mutate.py +1613 -0
  92. ectype/temporal/__init__.py +80 -0
  93. ectype/temporal/contract.py +221 -0
  94. ectype/temporal/detect.py +431 -0
  95. ectype/temporal/events.py +946 -0
  96. ectype/temporal/panel.py +937 -0
  97. ectype/temporal/pipeline.py +192 -0
  98. ectype/temporal/regular.py +674 -0
  99. ectype/types.py +46 -0
  100. ectype/validation/__init__.py +1 -0
  101. ectype/validation/metrics/__init__.py +7 -0
  102. ectype/validation/metrics/base.py +68 -0
  103. ectype/validation/metrics/bivariate.py +353 -0
  104. ectype/validation/metrics/missingness.py +54 -0
  105. ectype/validation/metrics/multivariate.py +265 -0
  106. ectype/validation/metrics/temporal.py +596 -0
  107. ectype/validation/metrics/univariate.py +514 -0
  108. ectype/validation/report.py +627 -0
  109. ectype/validation/validator.py +707 -0
  110. ectype_data-0.1.0.dist-info/METADATA +376 -0
  111. ectype_data-0.1.0.dist-info/RECORD +115 -0
  112. ectype_data-0.1.0.dist-info/WHEEL +4 -0
  113. ectype_data-0.1.0.dist-info/entry_points.txt +2 -0
  114. ectype_data-0.1.0.dist-info/licenses/LICENSE +192 -0
  115. ectype_data-0.1.0.dist-info/licenses/NOTICE +5 -0
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,130 @@
1
+ """Bivariate association profiler (M9).
2
+
3
+ ``association_matrix`` computes a pairwise association *strength* in [0, 1] with the
4
+ type-appropriate measure and ranks candidate dependent pairs. It is diagnostic: it is used to
5
+ prioritise which pairs get bivariate targets and is not stored as a target itself.
6
+
7
+ Measures:
8
+
9
+ * numeric-like x numeric-like (continuous, discrete, datetime, boolean): ``|spearman|``
10
+ * categorical x categorical/boolean: bias-corrected Cramer's V
11
+ * categorical x numeric: bias-corrected correlation ratio (eta)
12
+
13
+ Rows with a null in either column are dropped per pair. Data are subsampled deterministically
14
+ to at most ``max_rows`` rows (default 20000).
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ from itertools import combinations
20
+ from typing import Any
21
+
22
+ import numpy as np
23
+ import polars as pl
24
+
25
+ from ectype.fingerprint.disclosure import coarsen, resolve_policy
26
+ from ectype.fingerprint.schema import ColumnSchema, DisclosurePolicySpec
27
+ from ectype.rng import stream
28
+ from ectype.types import LogicalType
29
+ from ectype.validation.metrics.bivariate import (
30
+ correlation_ratio,
31
+ cramers_v,
32
+ spearman,
33
+ )
34
+ from ectype.validation.metrics.univariate import (
35
+ category_codes_from_data,
36
+ is_category,
37
+ is_numeric_like,
38
+ numeric_values,
39
+ )
40
+
41
+
42
+ def _measure_for(a: ColumnSchema, b: ColumnSchema) -> str | None:
43
+ cat_a = a.logical_type == LogicalType.CATEGORICAL
44
+ cat_b = b.logical_type == LogicalType.CATEGORICAL
45
+ if is_numeric_like(a) and is_numeric_like(b):
46
+ return "spearman"
47
+ if (cat_a or cat_b) and is_category(a) and is_category(b):
48
+ return "cramers_v"
49
+ if (cat_a and is_numeric_like(b)) or (cat_b and is_numeric_like(a)):
50
+ return "correlation_ratio"
51
+ return None
52
+
53
+
54
+ def association_matrix(df: pl.DataFrame, columns: list[ColumnSchema],
55
+ policy: DisclosurePolicySpec | str | None = None, *,
56
+ max_pairs: int = 200, max_rows: int = 20_000, seed: int = 0
57
+ ) -> dict[str, Any]:
58
+ """Pairwise association strengths and ranked candidate dependent pairs.
59
+
60
+ Returns a JSON-safe dict::
61
+
62
+ {"columns": [...], "matrix": [[...]], # symmetric strengths (diag 1, NaN -> 0)
63
+ "pairs": [{"columns": [a, b], "measure": m, "strength": s}, ...], # all, sorted desc
64
+ "candidates": [...], # dependent pairs (s > threshold), <= max_pairs
65
+ "diagnostics": {"n_rows_used", "n_pairs", "threshold", "skipped_columns", ...}}
66
+ """
67
+ pol = resolve_policy(policy)
68
+ usable = [c for c in columns if is_numeric_like(c) or is_category(c)]
69
+ skipped = [c.name for c in columns if c not in usable]
70
+ if df.height > max_rows:
71
+ idx = np.sort(stream(seed, "association", df.height).choice(df.height, max_rows,
72
+ replace=False))
73
+ sub = df.select([c.name for c in usable])[idx]
74
+ else:
75
+ sub = df.select([c.name for c in usable])
76
+ n = sub.height
77
+
78
+ num: dict[str, np.ndarray] = {}
79
+ cat: dict[str, tuple[np.ndarray, int]] = {}
80
+ for c in usable:
81
+ if is_numeric_like(c):
82
+ num[c.name] = numeric_values(sub[c.name], c)
83
+ if c.logical_type in (LogicalType.CATEGORICAL, LogicalType.BOOLEAN):
84
+ labels, codes, _ = category_codes_from_data(sub[c.name], pol)
85
+ cat[c.name] = (codes, len(labels))
86
+
87
+ names = [c.name for c in usable]
88
+ pos = {nm: i for i, nm in enumerate(names)}
89
+ mat = np.eye(len(names))
90
+ pairs: list[dict[str, Any]] = []
91
+ for a, b in combinations(usable, 2):
92
+ m = _measure_for(a, b)
93
+ if m is None:
94
+ continue
95
+ if m == "spearman":
96
+ s = abs(spearman(num[a.name], num[b.name]))
97
+ elif m == "cramers_v":
98
+ ca, ka = cat[a.name]
99
+ cb, kb = cat[b.name]
100
+ ok = np.isfinite(ca) & np.isfinite(cb)
101
+ s = cramers_v(ca[ok].astype(np.int64), cb[ok].astype(np.int64), ka, kb,
102
+ bias_correct=True)
103
+ else:
104
+ ccol, ncol = (a, b) if a.logical_type == LogicalType.CATEGORICAL else (b, a)
105
+ codes, k = cat[ccol.name]
106
+ y = num[ncol.name]
107
+ ok = np.isfinite(codes) & np.isfinite(y)
108
+ s = correlation_ratio(codes[ok].astype(np.int64), y[ok], k, bias_correct=True)
109
+ s = float(np.clip(s if np.isfinite(s) else 0.0, 0.0, 1.0))
110
+ s = coarsen(s, pol)
111
+ mat[pos[a.name], pos[b.name]] = mat[pos[b.name], pos[a.name]] = s
112
+ pairs.append({"columns": [a.name, b.name], "measure": m, "strength": s})
113
+
114
+ pairs.sort(key=lambda p: (-p["strength"], p["columns"][0], p["columns"][1]))
115
+ threshold = float(max(0.05, 3.0 / np.sqrt(max(n, 1))))
116
+ candidates = [p for p in pairs if p["strength"] > threshold][:max_pairs]
117
+ return {
118
+ "columns": names,
119
+ "matrix": [[float(v) for v in row] for row in mat],
120
+ "pairs": pairs,
121
+ "candidates": candidates,
122
+ "diagnostics": {
123
+ "n_rows_used": int(n),
124
+ "n_pairs": len(pairs),
125
+ "n_candidates": len(candidates),
126
+ "threshold": coarsen(threshold, pol),
127
+ "skipped_columns": skipped,
128
+ "max_pairs": int(max_pairs),
129
+ },
130
+ }