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/reporting/view.py
ADDED
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
"""The profile report's own view of a fingerprint: plain data, no engine types.
|
|
2
|
+
|
|
3
|
+
This module is the contract between the two halves of the report (ADR-0016):
|
|
4
|
+
|
|
5
|
+
* :mod:`ectype.reporting.adapter` is the only module that knows the fingerprint: manifest
|
|
6
|
+
field names, model kinds, array names, diagnostics. It turns a fingerprint into a
|
|
7
|
+
:class:`ReportView`.
|
|
8
|
+
* :mod:`ectype.reporting.findings`, :mod:`ectype.reporting.charts` and
|
|
9
|
+
:mod:`ectype.reporting.render` only ever see a :class:`ReportView`. They import nothing from
|
|
10
|
+
the engine (``tests/report/test_report_boundary.py`` enforces it).
|
|
11
|
+
|
|
12
|
+
Rules for everything in this file
|
|
13
|
+
---------------------------------
|
|
14
|
+
* Standard library only. Every field is a ``str``, ``int``, ``float``, ``bool``, ``None``, a
|
|
15
|
+
list of those, or another dataclass of this module, so a view converts to JSON with
|
|
16
|
+
:func:`dataclasses.asdict` and can be written by hand in a test.
|
|
17
|
+
* Every field has a default, and "not known" is always representable (``None`` or empty): the
|
|
18
|
+
adapter fills what it could read and the renderer must cope with anything missing.
|
|
19
|
+
* Strings that come from the fingerprint (column names, labels, notes, expressions, kinds) are
|
|
20
|
+
carried verbatim. They are untrusted: the renderer escapes all of them.
|
|
21
|
+
* Raw vocabulary (a role, a logical type, a model kind, a measure) is carried as the string the
|
|
22
|
+
fingerprint holds. The renderer has friendly names for the ones it knows and shows any other
|
|
23
|
+
as it is, so a new kind never needs a change here.
|
|
24
|
+
* Shares are fractions in ``[0, 1]``. Dates and durations are numbers in a stated unit.
|
|
25
|
+
|
|
26
|
+
Adding a field is free. Renaming or removing one, or changing its meaning, needs
|
|
27
|
+
:data:`VIEW_VERSION` raised and the renderer updated in the same change.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
from __future__ import annotations
|
|
31
|
+
|
|
32
|
+
from dataclasses import asdict, dataclass, field
|
|
33
|
+
from typing import Any
|
|
34
|
+
|
|
35
|
+
#: version of this view model (not of the fingerprint format, which the report never changes)
|
|
36
|
+
VIEW_VERSION = 1
|
|
37
|
+
|
|
38
|
+
# -- vocabulary the adapter normalises to (anything else is passed through as found) ----------
|
|
39
|
+
|
|
40
|
+
#: how a column is produced, in the report's words (:attr:`ColumnView.handling`)
|
|
41
|
+
HANDLINGS = (
|
|
42
|
+
"modeled", # has a fitted column model of its own
|
|
43
|
+
"computed", # a formula of another column (a derived column or an identity)
|
|
44
|
+
"offset", # another column plus or minus a modeled gap (a difference)
|
|
45
|
+
"share", # a modeled share of a total (a part of a split sum)
|
|
46
|
+
"total", # the sum of its parts
|
|
47
|
+
"identifier", # unique key: regenerated, nothing of it is stored
|
|
48
|
+
"reference", # repeating key: its group sizes are modeled, values are issued fresh
|
|
49
|
+
"pseudonym", # modeled, labels replaced by stand-in tokens
|
|
50
|
+
"constant", # one value
|
|
51
|
+
"excluded", # left out of the model (free text, structured strings)
|
|
52
|
+
"unknown", # a role or arrangement this version of the report does not know
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
#: what a histogram's axis measures (:attr:`Histogram.axis`)
|
|
56
|
+
AXES = ("number", "date", "duration", "share")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# -- small pieces -----------------------------------------------------------------------------
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@dataclass
|
|
63
|
+
class Fact:
|
|
64
|
+
"""One labelled value, already worded by the adapter only where the value is a raw string
|
|
65
|
+
of the fingerprint (a version, a policy name); numbers stay numbers in ``number``."""
|
|
66
|
+
|
|
67
|
+
label: str = ""
|
|
68
|
+
text: str = "" # the value as text, when it is text
|
|
69
|
+
number: float | None = None # the value as a number, when it is one
|
|
70
|
+
unit: str = "" # "", "share", "rows", "columns", "date:<unit>", ...
|
|
71
|
+
note: str = ""
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@dataclass
|
|
75
|
+
class Unread:
|
|
76
|
+
"""Something in the fingerprint the adapter did not interpret.
|
|
77
|
+
|
|
78
|
+
The page lists every one of these ("a section this version of the report does not
|
|
79
|
+
describe"), so nothing is dropped silently. ``where`` is a dotted location such as
|
|
80
|
+
``model.marginals.price`` or ``model.widgets``; ``what`` says what was found there
|
|
81
|
+
(``"unknown model kind 'beta_prime'"``, ``"unknown section"``); ``entries`` is how many
|
|
82
|
+
items it holds when that is countable; ``reason`` is the error text when reading failed.
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
where: str = ""
|
|
86
|
+
what: str = ""
|
|
87
|
+
entries: int | None = None
|
|
88
|
+
reason: str = ""
|
|
89
|
+
column: str | None = None
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
# -- distributions ----------------------------------------------------------------------------
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@dataclass
|
|
96
|
+
class Atom:
|
|
97
|
+
"""A point mass: one exact value that holds ``share`` of the non-missing rows."""
|
|
98
|
+
|
|
99
|
+
value: float = 0.0
|
|
100
|
+
share: float = 0.0
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@dataclass
|
|
104
|
+
class Histogram:
|
|
105
|
+
"""A numeric, date or duration distribution rebuilt from the fitted column model.
|
|
106
|
+
|
|
107
|
+
``edges`` has one more entry than ``shares``. Bins are evenly spaced in ``edges`` on a
|
|
108
|
+
linear scale, or in ``log10(edges)`` when ``scale == "log"`` (all edges positive then).
|
|
109
|
+
``shares`` are shares of the non-missing rows *excluding* the ``atoms``, which are drawn as
|
|
110
|
+
separate marks; the shares and the atoms together add up to about 1. ``quantiles`` are
|
|
111
|
+
``(probability, value)`` pairs of the whole distribution, atoms included, and always
|
|
112
|
+
contain 0.05, 0.25, 0.5, 0.75 and 0.95 when the model could be evaluated.
|
|
113
|
+
|
|
114
|
+
``axis`` says what the values are: ``"number"``; ``"date"`` (epoch values in ``unit``:
|
|
115
|
+
``"d"`` days, ``"ms"``, ``"us"`` or ``"ns"``); ``"duration"`` (a length of time in
|
|
116
|
+
``unit``); ``"share"`` (a fraction of a total). ``low`` and ``high`` are the ends of the
|
|
117
|
+
stored range; with ``clipped`` they are the policy's clip points, not the true extremes.
|
|
118
|
+
|
|
119
|
+
A column whose model holds a single value has no bins: ``edges`` and ``shares`` are empty
|
|
120
|
+
and ``atoms`` is that one value with share 1.
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
edges: list[float] = field(default_factory=list)
|
|
124
|
+
shares: list[float] = field(default_factory=list)
|
|
125
|
+
scale: str = "linear"
|
|
126
|
+
axis: str = "number"
|
|
127
|
+
unit: str = ""
|
|
128
|
+
atoms: list[Atom] = field(default_factory=list)
|
|
129
|
+
n_atoms: int = 0 # all point masses the model holds (atoms: largest)
|
|
130
|
+
heap_steps: list[float] = field(default_factory=list) # values heap on multiples of these
|
|
131
|
+
quantiles: list[list[float]] = field(default_factory=list)
|
|
132
|
+
mean: float | None = None
|
|
133
|
+
sd: float | None = None
|
|
134
|
+
low: float | None = None
|
|
135
|
+
high: float | None = None
|
|
136
|
+
clipped: bool = False
|
|
137
|
+
integer: bool = False
|
|
138
|
+
decimals: int | None = None
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@dataclass
|
|
142
|
+
class Level:
|
|
143
|
+
"""One bar of a :class:`Levels` chart. ``kind`` is ``"level"`` (a value of the column),
|
|
144
|
+
``"pooled"`` (the bucket the policy pooled rare values into) or ``"rest"`` (the levels the
|
|
145
|
+
page does not list one by one, added up)."""
|
|
146
|
+
|
|
147
|
+
label: str = ""
|
|
148
|
+
share: float = 0.0
|
|
149
|
+
kind: str = "level"
|
|
150
|
+
count: int | None = None # "rest": how many levels are added up
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
@dataclass
|
|
154
|
+
class Levels:
|
|
155
|
+
"""A distribution over labelled values: categories, booleans, integers with few values.
|
|
156
|
+
|
|
157
|
+
``bars`` are the largest levels first (or in value order when ``ordered``), then a
|
|
158
|
+
``"rest"`` bar when there are more, then the ``"pooled"`` bar when the policy pooled rare
|
|
159
|
+
values. ``n_levels`` counts the stored levels without the pooled bucket; ``n_pooled`` is
|
|
160
|
+
how many source values were pooled (``None`` when not recorded). With ``stand_ins`` the
|
|
161
|
+
labels are stand-in tokens, not source values.
|
|
162
|
+
"""
|
|
163
|
+
|
|
164
|
+
bars: list[Level] = field(default_factory=list)
|
|
165
|
+
n_levels: int | None = None
|
|
166
|
+
n_pooled: int | None = None
|
|
167
|
+
pooled_share: float | None = None
|
|
168
|
+
ordered: bool = False
|
|
169
|
+
stand_ins: bool = False
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
# -- columns ----------------------------------------------------------------------------------
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
@dataclass
|
|
176
|
+
class ColumnView:
|
|
177
|
+
"""One source column.
|
|
178
|
+
|
|
179
|
+
At most one of ``histogram`` and ``levels`` is set; both are ``None`` when the fingerprint
|
|
180
|
+
holds no distribution for the column (an identifier, a constant, a computed or excluded
|
|
181
|
+
column, a model kind the adapter cannot evaluate). ``chart_of`` says what the chart shows
|
|
182
|
+
when it is not the column's own values: ``"gap"`` (the gap to ``inputs[0]`` of an
|
|
183
|
+
``offset`` column), ``"share"`` (the share of ``inputs[0]``, its total) or ``"group
|
|
184
|
+
sizes"`` (rows per key of a ``reference`` column). ``chart_note`` is a caveat about the
|
|
185
|
+
chart, in a sentence (for example that the model kind is unknown and the chart was drawn
|
|
186
|
+
from stored quantiles).
|
|
187
|
+
"""
|
|
188
|
+
|
|
189
|
+
name: str = ""
|
|
190
|
+
index: int = 0 # position in the source table, from 0
|
|
191
|
+
logical_type: str = "" # as stored: "continuous", "categorical", ...
|
|
192
|
+
role: str = "" # as stored: "feature", "pseudonym", ...
|
|
193
|
+
handling: str = "unknown" # one of HANDLINGS
|
|
194
|
+
dtype: str = "" # physical type of the source column
|
|
195
|
+
missing: float | None = None # share of rows that are empty
|
|
196
|
+
distinct: int | None = None # approximate (the policy may coarsen it)
|
|
197
|
+
model_kind: str | None = None # kind of the fitted column model, as stored
|
|
198
|
+
slab_kind: str | None = None # for a mixed model: the kind of its smooth part
|
|
199
|
+
histogram: Histogram | None = None
|
|
200
|
+
levels: Levels | None = None
|
|
201
|
+
chart_of: str = "" # "", "gap", "share", "group sizes"
|
|
202
|
+
chart_note: str = ""
|
|
203
|
+
formula: str = "" # computed / offset / total: how it is computed
|
|
204
|
+
inputs: list[str] = field(default_factory=list) # columns it is computed from
|
|
205
|
+
gap_sign: int = 0 # offset: +1 (input + gap) or -1 (input - gap)
|
|
206
|
+
constant: str | None = None # the single value of a constant column
|
|
207
|
+
conditional_on: str | None = None # modeled given this column (a tree of tables)
|
|
208
|
+
low: float | None = None # stored range (policy-clipped), numbers and dates
|
|
209
|
+
high: float | None = None
|
|
210
|
+
unit: str = "" # epoch unit of a date column
|
|
211
|
+
is_date: bool = False # a date without a time of day
|
|
212
|
+
integer: bool = False
|
|
213
|
+
decimals: int | None = None
|
|
214
|
+
pattern: str | None = None # shape of a structured string, e.g. "99-AAA"
|
|
215
|
+
confidence: float | None = None # of the inferred type and role
|
|
216
|
+
overridden: bool = False # type or role set by the user
|
|
217
|
+
personal: bool = False # the engine judged it personal-looking
|
|
218
|
+
stand_in_style: str | None = None # how a pseudonym's tokens are built, as stored
|
|
219
|
+
notes: list[str] = field(default_factory=list) # the engine's notes, verbatim
|
|
220
|
+
unread: list[Unread] = field(default_factory=list) # what could not be read about it
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
# -- relationships ----------------------------------------------------------------------------
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
@dataclass
|
|
227
|
+
class Pair:
|
|
228
|
+
"""Association between two columns. ``strength`` is in ``[0, 1]`` on ``measure`` (as
|
|
229
|
+
stored: ``"spearman"``, ``"cramers_v"``, ``"correlation_ratio"``, ...). ``sign`` is +1 or
|
|
230
|
+
-1 when the direction is known (rank correlations), else 0. ``explained_by`` names a
|
|
231
|
+
structure the engine found that accounts for the pair (``"sum"``, ``"computed"``,
|
|
232
|
+
``"offset"``, ``"entity"``, ``"ordering"``), or is empty."""
|
|
233
|
+
|
|
234
|
+
a: str = ""
|
|
235
|
+
b: str = ""
|
|
236
|
+
measure: str = ""
|
|
237
|
+
strength: float = 0.0
|
|
238
|
+
sign: int = 0
|
|
239
|
+
explained_by: str = ""
|
|
240
|
+
#: index into :attr:`Relationships.groups` when ``a`` (``b``) stands for a group of
|
|
241
|
+
#: near-identical columns: the pair is then the strongest between the two sides
|
|
242
|
+
a_group: int | None = None
|
|
243
|
+
b_group: int | None = None
|
|
244
|
+
collapsed: int = 0 # weaker pairs between the same two sides, left out
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
@dataclass
|
|
248
|
+
class ColumnGroup:
|
|
249
|
+
"""Columns that carry almost the same information: every measured pair among them is at
|
|
250
|
+
least ``weakest`` strong. The page states the group once instead of each of its pairs.
|
|
251
|
+
``explained_by`` is set when one structure accounts for all of it (see :class:`Pair`)."""
|
|
252
|
+
|
|
253
|
+
columns: list[str] = field(default_factory=list)
|
|
254
|
+
weakest: float | None = None
|
|
255
|
+
measure: str = "" # the measure of its pairs when they share one
|
|
256
|
+
explained_by: str = ""
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
@dataclass
|
|
260
|
+
class Matrix:
|
|
261
|
+
"""Pairwise association strengths of a few columns (``values[i][j]`` for
|
|
262
|
+
``columns[i]``, ``columns[j]``; symmetric, diagonal 1). The adapter caps its size."""
|
|
263
|
+
|
|
264
|
+
columns: list[str] = field(default_factory=list)
|
|
265
|
+
values: list[list[float]] = field(default_factory=list)
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
@dataclass
|
|
269
|
+
class Relationships:
|
|
270
|
+
#: strongest first, capped; pairs inside one of ``groups`` are left out, and of the pairs
|
|
271
|
+
#: between two groups (or a group and a column) only the strongest is kept
|
|
272
|
+
pairs: list[Pair] = field(default_factory=list)
|
|
273
|
+
groups: list[ColumnGroup] = field(default_factory=list)
|
|
274
|
+
n_pairs: int | None = None # pairs the engine measured in all
|
|
275
|
+
n_columns: int | None = None # columns that took part
|
|
276
|
+
n_notable: int | None = None # pairs above the engine's own threshold
|
|
277
|
+
threshold: float | None = None
|
|
278
|
+
matrix: Matrix | None = None
|
|
279
|
+
joint_kind: str | None = None # model of how columns move together, as stored
|
|
280
|
+
joint_columns: int | None = None
|
|
281
|
+
joint_facts: list[Fact] = field(default_factory=list)
|
|
282
|
+
#: why the engine fitted this model, in the engine's own words (``diagnostics["joint"]``)
|
|
283
|
+
joint_reason: str | None = None
|
|
284
|
+
#: what the engine limited to keep the fit short, in its own words; None when nothing was
|
|
285
|
+
joint_limit: str | None = None
|
|
286
|
+
#: columns left out of the association screen, with the engine's reason category
|
|
287
|
+
left_out: list[str] = field(default_factory=list)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
# -- structure --------------------------------------------------------------------------------
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
@dataclass
|
|
294
|
+
class Ordering:
|
|
295
|
+
"""``lower <= target <= upper`` on every generated row. ``how`` is ``"gap"`` (the target
|
|
296
|
+
is ``base`` plus or minus a modeled gap; ``gap`` then holds the gap's distribution),
|
|
297
|
+
``"redraw"`` (the target keeps its own model and a row that breaks the order is drawn
|
|
298
|
+
again) or the method string found. ``exceptions`` is the share of source rows that break
|
|
299
|
+
it, when recorded; ``signed`` says those rows are reproduced rather than ruled out."""
|
|
300
|
+
|
|
301
|
+
target: str = ""
|
|
302
|
+
lower: list[str] = field(default_factory=list)
|
|
303
|
+
upper: list[str] = field(default_factory=list)
|
|
304
|
+
strict: bool = False
|
|
305
|
+
how: str = ""
|
|
306
|
+
base: str | None = None
|
|
307
|
+
gap: Histogram | None = None
|
|
308
|
+
signed: bool = False
|
|
309
|
+
exceptions: float | None = None
|
|
310
|
+
source: str = "" # "detected", "suggested", "confirmed", "user"
|
|
311
|
+
constraint: str | None = None
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
@dataclass
|
|
315
|
+
class Computed:
|
|
316
|
+
"""A column that is a formula of others. ``family`` is the engine's name for the kind of
|
|
317
|
+
function (``"calendar"``, ``"step"``, ``"periodic"``, ``"identity"``, ``"declared"``)."""
|
|
318
|
+
|
|
319
|
+
column: str = ""
|
|
320
|
+
formula: str = ""
|
|
321
|
+
inputs: list[str] = field(default_factory=list)
|
|
322
|
+
family: str = ""
|
|
323
|
+
exceptions: float | None = None # share of source rows that do not follow it
|
|
324
|
+
segments: int | None = None # step functions: number of bands
|
|
325
|
+
source: str = ""
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
@dataclass
|
|
329
|
+
class SumRule:
|
|
330
|
+
"""A total and its parts. ``total`` is a column, or ``None`` when the parts add up to
|
|
331
|
+
``constant``. ``mode`` is as stored (``"split"``, ``"scale"``, ``"sum"``); ``mean_shares``
|
|
332
|
+
is each part's mean share of the total, aligned with ``parts`` (empty when not stored)."""
|
|
333
|
+
|
|
334
|
+
total: str | None = None
|
|
335
|
+
constant: float | None = None
|
|
336
|
+
parts: list[str] = field(default_factory=list)
|
|
337
|
+
signs: list[int] = field(default_factory=list)
|
|
338
|
+
mode: str = ""
|
|
339
|
+
rounding: str = ""
|
|
340
|
+
mean_shares: list[float] = field(default_factory=list)
|
|
341
|
+
exceptions: float | None = None
|
|
342
|
+
tolerance: float | None = None
|
|
343
|
+
source: str = ""
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
@dataclass
|
|
347
|
+
class EntityAttribute:
|
|
348
|
+
column: str = ""
|
|
349
|
+
entries: int | None = None # keys that have a value for it
|
|
350
|
+
exceptions: float | None = None # share of source rows that disagree with their key
|
|
351
|
+
anchor: bool = False # the column the key follows, not a looked-up one
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
@dataclass
|
|
355
|
+
class EntityGroup:
|
|
356
|
+
"""A key column and the columns that are attributes of the entity it names."""
|
|
357
|
+
|
|
358
|
+
key: str = ""
|
|
359
|
+
n_keys: int | None = None
|
|
360
|
+
attributes: list[EntityAttribute] = field(default_factory=list)
|
|
361
|
+
source: str = ""
|
|
362
|
+
key_stand_ins: bool = False
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
@dataclass
|
|
366
|
+
class ReferenceKey:
|
|
367
|
+
"""A key that repeats: rows per key are modeled, key values are issued fresh."""
|
|
368
|
+
|
|
369
|
+
column: str = ""
|
|
370
|
+
mean_group: float | None = None # mean rows per key
|
|
371
|
+
max_group: float | None = None
|
|
372
|
+
singletons: float | None = None # share of keys that occur once
|
|
373
|
+
facts: list[Fact] = field(default_factory=list)
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
@dataclass
|
|
377
|
+
class WeeklyPattern:
|
|
378
|
+
"""Share of rows per weekday of a date column, Monday first (seven numbers), or empty when
|
|
379
|
+
the column only follows the columns in ``tied_to``."""
|
|
380
|
+
|
|
381
|
+
column: str = ""
|
|
382
|
+
weekday_shares: list[float] = field(default_factory=list)
|
|
383
|
+
tied_to: list[str] = field(default_factory=list)
|
|
384
|
+
period: int = 7
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
@dataclass
|
|
388
|
+
class Constraint:
|
|
389
|
+
"""A rule over rows. ``status`` is ``"confirmed"`` (enforced) or ``"suggested"`` (found by
|
|
390
|
+
the engine, not enforced until confirmed)."""
|
|
391
|
+
|
|
392
|
+
id: str = ""
|
|
393
|
+
expression: str = ""
|
|
394
|
+
status: str = "suggested"
|
|
395
|
+
family: str = ""
|
|
396
|
+
description: str = ""
|
|
397
|
+
confidence: str = "" # "low", "medium", "high"
|
|
398
|
+
support: int | None = None
|
|
399
|
+
violations: int | None = None
|
|
400
|
+
enforcement: str = ""
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
@dataclass
|
|
404
|
+
class NotApplied:
|
|
405
|
+
"""A structure the engine considered and turned down, with its reason (verbatim)."""
|
|
406
|
+
|
|
407
|
+
kind: str = "" # "ordering", "computed", "sum", "entity", "weekly"
|
|
408
|
+
subject: str = "" # the columns or expression concerned
|
|
409
|
+
reason: str = ""
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
@dataclass
|
|
413
|
+
class Structure:
|
|
414
|
+
orderings: list[Ordering] = field(default_factory=list)
|
|
415
|
+
computed: list[Computed] = field(default_factory=list)
|
|
416
|
+
sums: list[SumRule] = field(default_factory=list)
|
|
417
|
+
entities: list[EntityGroup] = field(default_factory=list)
|
|
418
|
+
references: list[ReferenceKey] = field(default_factory=list)
|
|
419
|
+
weekly: list[WeeklyPattern] = field(default_factory=list)
|
|
420
|
+
confirmed: list[Constraint] = field(default_factory=list)
|
|
421
|
+
suggested: list[Constraint] = field(default_factory=list) # capped; see n_suggested
|
|
422
|
+
n_suggested: int = 0
|
|
423
|
+
suggested_families: list[Fact] = field(default_factory=list) # family -> count
|
|
424
|
+
not_applied: list[NotApplied] = field(default_factory=list) # capped; see n_not_applied
|
|
425
|
+
n_not_applied: int = 0
|
|
426
|
+
mode: str = "" # the profiler's structure setting, as stored
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
# -- privacy ----------------------------------------------------------------------------------
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
@dataclass
|
|
433
|
+
class PersonalColumn:
|
|
434
|
+
"""A column the engine treats as personal or as a key. ``handling`` is one of
|
|
435
|
+
``"pseudonym"``, ``"identifier"``, ``"reference"``, ``"excluded"``."""
|
|
436
|
+
|
|
437
|
+
column: str = ""
|
|
438
|
+
handling: str = ""
|
|
439
|
+
style: str = "" # stand-in style, as stored ("indexed", "shape")
|
|
440
|
+
reason: str = "" # the engine's note on why, verbatim
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
@dataclass
|
|
444
|
+
class PooledColumn:
|
|
445
|
+
column: str = ""
|
|
446
|
+
n_pooled: int | None = None # source values pooled into the bucket
|
|
447
|
+
share: float | None = None # share of rows in the bucket
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
@dataclass
|
|
451
|
+
class Privacy:
|
|
452
|
+
policy: str = "" # profile name, as stored
|
|
453
|
+
sensitive: bool = False # the policy marks the fingerprint as sensitive
|
|
454
|
+
min_category_support: int | None = None
|
|
455
|
+
quantile_resolution: int | None = None
|
|
456
|
+
tail_clip: list[float] = field(default_factory=list) # [low, high] probabilities
|
|
457
|
+
rare_cell_min: int | None = None
|
|
458
|
+
significant_digits: int | None = None
|
|
459
|
+
identifiers: str = "" # identifier rule, as stored ("regenerate")
|
|
460
|
+
smallest_stored_support: int | None = None
|
|
461
|
+
personal: list[PersonalColumn] = field(default_factory=list)
|
|
462
|
+
pooled: list[PooledColumn] = field(default_factory=list)
|
|
463
|
+
coarse_columns: list[str] = field(default_factory=list) # stored as mean and spread only
|
|
464
|
+
warnings: list[str] = field(default_factory=list) # the engine's, verbatim
|
|
465
|
+
other_facts: list[Fact] = field(default_factory=list) # policy fields not known above
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
# -- the whole report -------------------------------------------------------------------------
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
@dataclass
|
|
472
|
+
class Overview:
|
|
473
|
+
name: str = ""
|
|
474
|
+
description: str = ""
|
|
475
|
+
rows: int | None = None
|
|
476
|
+
columns: int | None = None # columns of the source table
|
|
477
|
+
format_version: str = ""
|
|
478
|
+
engine_version: str = ""
|
|
479
|
+
created: str = "" # ISO timestamp, as stored
|
|
480
|
+
content_id: str = "" # short identity of the fingerprint's content
|
|
481
|
+
policy: str = ""
|
|
482
|
+
fit_seed: int | None = None
|
|
483
|
+
lineage: list[str] = field(default_factory=list) # operations that produced it, in order
|
|
484
|
+
targets_calibration: int | None = None
|
|
485
|
+
targets_sealed: int | None = None
|
|
486
|
+
older_format: bool = False # written by an older format than the reader's
|
|
487
|
+
newer_format: bool = False # written by a newer one (fields may be ignored)
|
|
488
|
+
reader_format: str = "" # format version of the engine that read it
|
|
489
|
+
reader_engine: str = "" # version of the engine that built the view
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
@dataclass
|
|
493
|
+
class ReportView:
|
|
494
|
+
"""Everything the page shows about one fingerprint."""
|
|
495
|
+
|
|
496
|
+
view_version: int = VIEW_VERSION
|
|
497
|
+
overview: Overview = field(default_factory=Overview)
|
|
498
|
+
columns: list[ColumnView] = field(default_factory=list)
|
|
499
|
+
relationships: Relationships = field(default_factory=Relationships)
|
|
500
|
+
structure: Structure = field(default_factory=Structure)
|
|
501
|
+
privacy: Privacy = field(default_factory=Privacy)
|
|
502
|
+
#: what the adapter found and did not interpret (never dropped silently)
|
|
503
|
+
unread: list[Unread] = field(default_factory=list)
|
|
504
|
+
#: temporal / population / relational sections that are present, by name
|
|
505
|
+
extra_sections: list[str] = field(default_factory=list)
|
|
506
|
+
|
|
507
|
+
def column(self, name: str) -> ColumnView | None:
|
|
508
|
+
for c in self.columns:
|
|
509
|
+
if c.name == name:
|
|
510
|
+
return c
|
|
511
|
+
return None
|
|
512
|
+
|
|
513
|
+
def all_unread(self) -> list[Unread]:
|
|
514
|
+
"""Table-level and column-level unread items together."""
|
|
515
|
+
return [*self.unread, *(u for c in self.columns for u in c.unread)]
|
|
516
|
+
|
|
517
|
+
def to_dict(self) -> dict[str, Any]:
|
|
518
|
+
return asdict(self)
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
# -- comparison of two fingerprints ------------------------------------------------------------
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
@dataclass
|
|
525
|
+
class DriftColumn:
|
|
526
|
+
"""One column in a comparison of two fingerprints (``a`` the reference, ``b`` the
|
|
527
|
+
candidate). ``status`` is ``"drifted"`` (some measured property moved by more than
|
|
528
|
+
sampling noise explains), ``"changed"`` (its type, role or category set differs),
|
|
529
|
+
``"added"`` (only in ``b``), ``"removed"`` (only in ``a``) or ``"steady"``. ``score`` is
|
|
530
|
+
the engine's ranking score (0 when steady); ``worst_metric`` and ``worst_ratio`` describe
|
|
531
|
+
the drifted target furthest beyond its decision threshold (ratio = distance / threshold).
|
|
532
|
+
``changes`` are sentences about schema changes, ready to print."""
|
|
533
|
+
|
|
534
|
+
name: str = ""
|
|
535
|
+
status: str = "steady"
|
|
536
|
+
score: float = 0.0
|
|
537
|
+
n_drifted: int = 0
|
|
538
|
+
worst_metric: str = ""
|
|
539
|
+
worst_ratio: float | None = None
|
|
540
|
+
changes: list[str] = field(default_factory=list)
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
@dataclass
|
|
544
|
+
class DriftPair:
|
|
545
|
+
"""A pair of columns whose joint behaviour moved, with the engine's ranking score."""
|
|
546
|
+
|
|
547
|
+
a: str = ""
|
|
548
|
+
b: str = ""
|
|
549
|
+
score: float = 0.0
|
|
550
|
+
n_drifted: int = 0
|
|
551
|
+
worst_metric: str = ""
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
@dataclass
|
|
555
|
+
class DriftView:
|
|
556
|
+
"""Everything the comparison page shows. ``a`` and ``b`` are the full views of the two
|
|
557
|
+
fingerprints; ``columns`` lists every column of either, most changed first."""
|
|
558
|
+
|
|
559
|
+
view_version: int = VIEW_VERSION
|
|
560
|
+
verdict: str = "" # "drift", "none" or "inconclusive"
|
|
561
|
+
a: ReportView = field(default_factory=ReportView)
|
|
562
|
+
b: ReportView = field(default_factory=ReportView)
|
|
563
|
+
sensitivity: str = "" # as given: "strict", "standard", "lenient", a number
|
|
564
|
+
q: float | None = None # false-discovery rate of the decision
|
|
565
|
+
n_targets: int | None = None # measured properties compared
|
|
566
|
+
n_drifted: int | None = None # of which drifted
|
|
567
|
+
n_errors: int = 0 # properties that could not be compared
|
|
568
|
+
only_a: int = 0 # properties measured only in a
|
|
569
|
+
only_b: int = 0 # properties measured only in b
|
|
570
|
+
columns: list[DriftColumn] = field(default_factory=list)
|
|
571
|
+
pairs: list[DriftPair] = field(default_factory=list) # capped; see n_pairs
|
|
572
|
+
n_pairs: int = 0 # drifted pairs in all
|
|
573
|
+
notes: list[str] = field(default_factory=list) # the engine's schema notes
|
|
574
|
+
policy_warnings: list[str] = field(default_factory=list) # verbatim
|
|
575
|
+
unread: list[Unread] = field(default_factory=list)
|
|
576
|
+
|
|
577
|
+
def column(self, name: str) -> DriftColumn | None:
|
|
578
|
+
for c in self.columns:
|
|
579
|
+
if c.name == name:
|
|
580
|
+
return c
|
|
581
|
+
return None
|
|
582
|
+
|
|
583
|
+
def to_dict(self) -> dict[str, Any]:
|
|
584
|
+
return asdict(self)
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
__all__ = [
|
|
588
|
+
"AXES", "HANDLINGS", "VIEW_VERSION", "Atom", "ColumnGroup", "ColumnView", "Computed",
|
|
589
|
+
"Constraint", "DriftColumn", "DriftPair", "DriftView", "EntityAttribute", "EntityGroup",
|
|
590
|
+
"Fact", "Histogram", "Level", "Levels", "Matrix", "NotApplied", "Ordering", "Overview",
|
|
591
|
+
"Pair", "PersonalColumn", "PooledColumn", "Privacy", "ReferenceKey", "Relationships",
|
|
592
|
+
"ReportView", "Structure", "SumRule", "Unread", "WeeklyPattern",
|
|
593
|
+
]
|
ectype/rng.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Deterministic random streams.
|
|
2
|
+
|
|
3
|
+
All randomness flows from a root seed through ``numpy.random.SeedSequence``. Components derive
|
|
4
|
+
independent child streams by *name* (stable across runs and code reordering), never from
|
|
5
|
+
global state.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import hashlib
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _name_key(name: str) -> int:
|
|
16
|
+
return int.from_bytes(hashlib.sha256(name.encode("utf-8")).digest()[:8], "little")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def stream(seed: int | np.random.SeedSequence, *names: str | int) -> np.random.Generator:
|
|
20
|
+
"""Return a PCG64 generator for ``seed`` specialised by a path of names/ints.
|
|
21
|
+
|
|
22
|
+
``stream(42, "marginal", "age", "chunk", 3)`` is stable regardless of what other streams
|
|
23
|
+
exist or in which order they are created.
|
|
24
|
+
"""
|
|
25
|
+
keys = [_name_key(n) if isinstance(n, str) else int(n) for n in names]
|
|
26
|
+
if isinstance(seed, np.random.SeedSequence):
|
|
27
|
+
# keep the sequence's own spawn path as a prefix, so spawned children stay distinct
|
|
28
|
+
entropy = seed.entropy
|
|
29
|
+
keys = [int(k) for k in seed.spawn_key] + keys
|
|
30
|
+
else:
|
|
31
|
+
entropy = int(seed)
|
|
32
|
+
ss = np.random.SeedSequence(entropy=entropy, spawn_key=tuple(keys))
|
|
33
|
+
return np.random.Generator(np.random.PCG64(ss))
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Scenario engine (M26): mutate, merge, interpolate and extrapolate fingerprints.
|
|
2
|
+
|
|
3
|
+
Importing this package registers the scenario model kinds (marginals ``affine``, ``mixture``,
|
|
4
|
+
``discrete_mixture`` and the joint ``mixture_of_fingerprints``), which fingerprints produced by
|
|
5
|
+
these operations need in order to load and generate.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from ectype.scenarios.merge import (
|
|
9
|
+
ExtrapolationResult,
|
|
10
|
+
MixtureOfFingerprints,
|
|
11
|
+
component_proportions,
|
|
12
|
+
extrapolate,
|
|
13
|
+
generate_merged,
|
|
14
|
+
interpolate,
|
|
15
|
+
merge,
|
|
16
|
+
)
|
|
17
|
+
from ectype.scenarios.mutate import AffineMarginal, ScenarioResult, mutate
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"AffineMarginal",
|
|
21
|
+
"ExtrapolationResult",
|
|
22
|
+
"MixtureOfFingerprints",
|
|
23
|
+
"ScenarioResult",
|
|
24
|
+
"component_proportions",
|
|
25
|
+
"extrapolate",
|
|
26
|
+
"generate_merged",
|
|
27
|
+
"interpolate",
|
|
28
|
+
"merge",
|
|
29
|
+
"mutate",
|
|
30
|
+
]
|