asofaudit 0.4.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.
- asofaudit-0.4.0/CONTRIBUTING.md +9 -0
- asofaudit-0.4.0/LICENSE +21 -0
- asofaudit-0.4.0/MANIFEST.in +2 -0
- asofaudit-0.4.0/PKG-INFO +276 -0
- asofaudit-0.4.0/README.md +266 -0
- asofaudit-0.4.0/examples/correct.csv +4 -0
- asofaudit-0.4.0/examples/feature-ages/ages.json +1 -0
- asofaudit-0.4.0/examples/feature-ages/history.csv +3 -0
- asofaudit-0.4.0/examples/feature-ages/requests.csv +2 -0
- asofaudit-0.4.0/examples/feature-ages/selected.csv +3 -0
- asofaudit-0.4.0/examples/feature-ages/stale.csv +3 -0
- asofaudit-0.4.0/examples/history.csv +4 -0
- asofaudit-0.4.0/examples/requests.csv +4 -0
- asofaudit-0.4.0/examples/selected.csv +4 -0
- asofaudit-0.4.0/pyproject.toml +23 -0
- asofaudit-0.4.0/setup.cfg +4 -0
- asofaudit-0.4.0/src/asofaudit/__init__.py +5 -0
- asofaudit-0.4.0/src/asofaudit/__main__.py +3 -0
- asofaudit-0.4.0/src/asofaudit/cli.py +112 -0
- asofaudit-0.4.0/src/asofaudit/core.py +435 -0
- asofaudit-0.4.0/src/asofaudit.egg-info/PKG-INFO +276 -0
- asofaudit-0.4.0/src/asofaudit.egg-info/SOURCES.txt +29 -0
- asofaudit-0.4.0/src/asofaudit.egg-info/dependency_links.txt +1 -0
- asofaudit-0.4.0/src/asofaudit.egg-info/entry_points.txt +2 -0
- asofaudit-0.4.0/src/asofaudit.egg-info/top_level.txt +1 -0
- asofaudit-0.4.0/tests/test_audit.py +549 -0
- asofaudit-0.4.0/tests/test_feature_ages.py +450 -0
- asofaudit-0.4.0/tests/test_fractional_timestamps.py +179 -0
- asofaudit-0.4.0/tests/test_output_failure.py +180 -0
- asofaudit-0.4.0/tests/test_strict_event.py +239 -0
- asofaudit-0.4.0/tests/test_sweep.py +216 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Open an issue for a proposed policy change before implementing it. Fixes need a
|
|
4
|
+
regression test and clear scope. Keep invalid/incomplete inputs distinct from a
|
|
5
|
+
complete report with violations. Do not claim an audit proves real availability
|
|
6
|
+
or absence of leakage.
|
|
7
|
+
|
|
8
|
+
Run the development checks in README.md. No contributor agreement or personal
|
|
9
|
+
attestation is requested. Contributions use this repository's MIT license.
|
asofaudit-0.4.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Anish Pentyala
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
asofaudit-0.4.0/PKG-INFO
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: asofaudit
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Offline bitemporal feature-selection audit against explicit version histories
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
|
|
11
|
+
# asofaudit
|
|
12
|
+
|
|
13
|
+
Check whether a training-data pipeline selected the feature versions that were
|
|
14
|
+
actually eligible at each prediction time, including late-arriving corrections.
|
|
15
|
+
No feature values, feature-store server, pandas, network access, or input code
|
|
16
|
+
execution are needed. Python 3.9+ with the standard-library `sqlite3` module.
|
|
17
|
+
|
|
18
|
+
This is a **version-selection audit**, not proof that a dataset is leakage-free.
|
|
19
|
+
It trusts your version history, identifiers, timestamps, and declared policy.
|
|
20
|
+
|
|
21
|
+
## A correction from the future
|
|
22
|
+
|
|
23
|
+
A customer's balance event happened January 1. The original version was known
|
|
24
|
+
that day. A correction was written January 10. Selecting the correction for a
|
|
25
|
+
January 2 prediction uses a version that was not yet known, even though its event
|
|
26
|
+
time is before the prediction. Selecting an older version after a newer eligible
|
|
27
|
+
event is another error that checking only `feature_time <= prediction_time` misses.
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
python -m pip install .
|
|
31
|
+
asofaudit examples/history.csv examples/requests.csv examples/selected.csv \
|
|
32
|
+
--feature balance --examples 5
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The example exits 1, with two violations: `not_yet_known` for `prediction-1` and
|
|
36
|
+
`not_latest` for `prediction-2`. The explicit empty selection for `prediction-3`
|
|
37
|
+
is correct because that entity has no eligible history. Replacing `selected.csv`
|
|
38
|
+
with `correct.csv` exits 0. This is source installation, not a PyPI release.
|
|
39
|
+
|
|
40
|
+
## Three explicit CSV manifests
|
|
41
|
+
|
|
42
|
+
| Input | Required columns |
|
|
43
|
+
|---|---|
|
|
44
|
+
| History | `version_id,entity_id,feature,event_at,known_at` |
|
|
45
|
+
| Requests | `request_id,entity_id,prediction_at` |
|
|
46
|
+
| Selections | `request_id,feature,version_id` |
|
|
47
|
+
|
|
48
|
+
- Headers must contain exactly these columns, in any order, without duplicates.
|
|
49
|
+
- UTF-8 or UTF-8 BOM, comma-delimited CSV with Python's strict CSV parser.
|
|
50
|
+
Quoted commas and multiline fields work. Ragged/blank data records are invalid.
|
|
51
|
+
This does not implement a separate complete CSV grammar validator.
|
|
52
|
+
- IDs and feature names are exact strings, without trimming or case folding.
|
|
53
|
+
`001` and `1` are different. Required fields cannot be blank/whitespace-only or
|
|
54
|
+
contain NUL. Only selection `version_id` may be empty, meaning no feature value.
|
|
55
|
+
There are no inferred null tokens: `NA` is an ordinary identifier.
|
|
56
|
+
- Version IDs are globally unique. Request IDs are unique. Each entity/feature
|
|
57
|
+
`(event_at, known_at)` pair must be unique after UTC normalization. Ambiguous
|
|
58
|
+
ties are invalid, even if they would not affect a requested prediction.
|
|
59
|
+
- Supply each desired feature with a repeated `--feature` option. Every request
|
|
60
|
+
must have **exactly one selection for every requested feature**, including an
|
|
61
|
+
empty version for no value. Missing rows are invalid, never silently skipped.
|
|
62
|
+
- Unknown selected version IDs, unknown requests, unrequested features, duplicate
|
|
63
|
+
selections, empty request files, and invalid history rows are input errors.
|
|
64
|
+
History may be empty. Extra history features/entities are allowed and validated.
|
|
65
|
+
|
|
66
|
+
Timestamps must have exactly the form `YYYY-MM-DDTHH:MM:SS[.ffffff](Z|+HH:MM|-HH:MM)`.
|
|
67
|
+
Fractions have 1-6 digits. Four-digit years 0001-9999, valid dates, seconds 00-59,
|
|
68
|
+
hours 00-23, and explicit offsets are required. No naive times, leap seconds,
|
|
69
|
+
24:00:00, timezone names, DST inference, or sub-microsecond rounding. All comparisons
|
|
70
|
+
use integer UTC microseconds, including dates before 1970. Fractional seconds
|
|
71
|
+
with 1-6 digits are padded exactly to microseconds on all supported Python
|
|
72
|
+
versions, including 3.9 and 3.10; no precision is rounded or truncated.
|
|
73
|
+
|
|
74
|
+
## Declared selection policy
|
|
75
|
+
|
|
76
|
+
For the request's exact entity and feature:
|
|
77
|
+
|
|
78
|
+
1. Keep versions with both `event_at <= prediction_at` and
|
|
79
|
+
`known_at <= prediction_at`. Equality is eligible.
|
|
80
|
+
2. With `--max-age-us N`, also require `prediction_at - event_at <= N`.
|
|
81
|
+
This is an inclusive, nonnegative **event-age** limit in microseconds, not an
|
|
82
|
+
ingestion-age limit. Omit it for no age limit.
|
|
83
|
+
3. Select the maximum `(event_at, known_at)` in that order. A newer eligible
|
|
84
|
+
event wins over a more recently learned correction to an older event.
|
|
85
|
+
4. If no version is eligible, expect an explicit empty selected version.
|
|
86
|
+
|
|
87
|
+
This policy is fixed, not inferred from the manifests. If your pipeline uses
|
|
88
|
+
strict known-before times, global snapshot cutoffs, aggregation windows, deletions,
|
|
89
|
+
priorities, or another tie-breaker, this model is not sufficient.
|
|
90
|
+
A version whose known time precedes its event time is permitted but still must
|
|
91
|
+
pass both eligibility comparisons.
|
|
92
|
+
|
|
93
|
+
### Different age limits for different features
|
|
94
|
+
|
|
95
|
+
Use `--feature-age-limits ages.json` instead of `--max-age-us` when features
|
|
96
|
+
have different declared freshness requirements:
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
{"balance": 86400000000, "plan": null}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
asofaudit history.csv requests.csv selected.csv \
|
|
104
|
+
--feature balance --feature plan --feature-age-limits ages.json --examples 5
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
A complete synthetic example is included:
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
asofaudit examples/feature-ages/history.csv examples/feature-ages/requests.csv \
|
|
111
|
+
examples/feature-ages/selected.csv --feature balance --feature plan \
|
|
112
|
+
--feature-age-limits examples/feature-ages/ages.json --examples 5
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
It exits 0: the two-day-old balance is explicitly absent and the equally old plan
|
|
116
|
+
is still eligible. Replacing `selected.csv` with `stale.csv` exits 1 with one
|
|
117
|
+
`expired` balance selection and an empty expected version.
|
|
118
|
+
|
|
119
|
+
This declares an inclusive one-day event-age limit for `balance` and explicitly
|
|
120
|
+
no age limit for `plan`. Both still require event and known times at or before
|
|
121
|
+
the prediction. It does not use the current clock or age since ingestion.
|
|
122
|
+
|
|
123
|
+
The JSON object must contain **exactly every requested feature**, with exact
|
|
124
|
+
names. No missing features, extras, defaults, or inheritance. Values are integer
|
|
125
|
+
microseconds from 0 through 315537897599999999, or `null` for unlimited. Booleans,
|
|
126
|
+
floats (including `1.0`), strings, negative or out-of-range values, duplicate
|
|
127
|
+
keys (including escaped aliases), and non-finite numbers are invalid. The file
|
|
128
|
+
must be UTF-8 (optional BOM), at most 1 MiB, and contain one JSON object. Invalid
|
|
129
|
+
policy or manifests exit 2 without a partial JSON report. The policy file is
|
|
130
|
+
read once and does not change the three CSV per-input byte/row limits.
|
|
131
|
+
|
|
132
|
+
The library equivalent is
|
|
133
|
+
`audit(..., features=['balance', 'plan'], feature_max_age_us={'balance': 86400000000, 'plan': None})`.
|
|
134
|
+
It copies the complete mapping before reading inputs. This mode cannot be
|
|
135
|
+
combined with a non-`None` global `max_age_us`. Omitting it preserves the existing
|
|
136
|
+
global/no-limit mode and report shape.
|
|
137
|
+
|
|
138
|
+
In this opt-in mode, schema-version-1 `policy` additionally contains the complete
|
|
139
|
+
normalized `feature_max_age_us` mapping; `max_age_us` is `null` because there is no
|
|
140
|
+
global limit. Consumers must read the per-feature mapping when present, not
|
|
141
|
+
interpret that global `null` as making every feature unlimited. The normalized
|
|
142
|
+
values are the policy used by the audit; the JSON file's raw bytes are not hashed
|
|
143
|
+
or added to the three CSV receipts. Keep the report if policy provenance matters.
|
|
144
|
+
This is explicit caller configuration, not an import of Feast feature-view TTLs
|
|
145
|
+
or a complete feature-store compatibility adapter.
|
|
146
|
+
|
|
147
|
+
A known selected version that violates the policy produces one reason, in this
|
|
148
|
+
precedence: `wrong_entity`, `wrong_feature`, `future_event`, `not_yet_known`,
|
|
149
|
+
`expired`, `not_latest`. An empty selection when a value exists is
|
|
150
|
+
`missing_selection`. The report lists the expected version only when examples
|
|
151
|
+
are requested. A wrong version can violate several rules; reason counts are
|
|
152
|
+
mutually exclusive, not a count of every possible defect.
|
|
153
|
+
|
|
154
|
+
## Reports and CI
|
|
155
|
+
|
|
156
|
+
```sh
|
|
157
|
+
asofaudit history.csv requests.csv selected.csv \
|
|
158
|
+
--feature balance --feature plan --max-age-us 604800000000 > audit.json
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
- Exit **0**: complete audit, every requested pair matches this policy.
|
|
162
|
+
- Exit **1**: complete audit, some pairs violate this policy. JSON remains complete.
|
|
163
|
+
- Exit **2**: invalid/incomplete inputs, bad options, resource limit, storage
|
|
164
|
+
error, or output I/O failure. Invalid input emits no JSON report on stdout.
|
|
165
|
+
Output failures cannot retract bytes already written to a failing pipe or
|
|
166
|
+
filesystem; those bytes are not a complete report. Diagnostics on stderr are
|
|
167
|
+
best effort if that destination also fails.
|
|
168
|
+
|
|
169
|
+
JSON schema version 1 includes counts, per-feature counts, mutually exclusive
|
|
170
|
+
reason counts, declared policy, and SHA256/byte/row counts of each input. Digests
|
|
171
|
+
bind the bytes actually read. They are not signatures, proof of history
|
|
172
|
+
completeness, or an atomic cross-file snapshot. Freeze the three manifests before
|
|
173
|
+
auditing; concurrent source edits are outside the guarantee.
|
|
174
|
+
|
|
175
|
+
Examples default to **0**. Use `--examples N` (0-1000) for bounded evidence in
|
|
176
|
+
request-ID order and then supplied feature order. Examples expose request IDs,
|
|
177
|
+
feature names, selected versions, and expected versions. Counts also disclose
|
|
178
|
+
feature names and dataset sizes. Treat reports as private when appropriate.
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
from asofaudit import audit
|
|
182
|
+
|
|
183
|
+
report = audit('history.csv', 'requests.csv', 'selected.csv',
|
|
184
|
+
features=['balance'], examples=0)
|
|
185
|
+
assert report['ok'] # Only the stated version-selection policy.
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Disk, limits, and privacy
|
|
189
|
+
|
|
190
|
+
Inputs are streamed into a new temporary SQLite database. There is no extraction,
|
|
191
|
+
network, telemetry, input modification, or automatic repair. Identifiers and
|
|
192
|
+
timestamps are written to disk in plaintext; feature values are never requested.
|
|
193
|
+
`--temp-dir DIR` selects an existing scratch parent. On POSIX, the new directory
|
|
194
|
+
is mode 0700 and database 0600. Windows permission equivalence is not claimed.
|
|
195
|
+
|
|
196
|
+
Normal completion and errors close/remove the database and scratch directory.
|
|
197
|
+
Removal is not secure erasure. Forced termination/power loss can leave files;
|
|
198
|
+
backups, filesystem snapshots and elevated access can expose them. Cleanup failure
|
|
199
|
+
is an error and may mask an earlier error. Choose scratch storage accordingly.
|
|
200
|
+
|
|
201
|
+
Limits default to 1,000,000 rows **per input**, 256 MiB bytes **per input**, and
|
|
202
|
+
1,000,000 request-feature pairs. Configure with `--max-rows`, `--max-bytes`, and
|
|
203
|
+
`--max-pairs`. Python's CSV field-size limit also applies. Crossing any limit fails
|
|
204
|
+
the whole audit. SQLite cache is advisory 8 MiB; this is not a hard RAM/disk/time
|
|
205
|
+
bound. SQLite indexes consume extra disk. Requests are evaluated internally in prediction-time order. Each history row
|
|
206
|
+
enters a partial lookup index only when its known time has arrived, avoiding
|
|
207
|
+
repeated scans over future corrections for every prediction. Bounded examples
|
|
208
|
+
still use request-ID order and supplied feature order, independent of evaluation
|
|
209
|
+
order. The database writes an eligibility flag and maintains an extra known-time
|
|
210
|
+
index; this can add disk/I/O cost on ordinary histories. No runtime bound or
|
|
211
|
+
large-scale performance claim is made.
|
|
212
|
+
|
|
213
|
+
## What this does not establish
|
|
214
|
+
|
|
215
|
+
The audit cannot prove that source timestamps are true, records are complete,
|
|
216
|
+
version IDs bind immutable payloads, or logged selections match the data actually
|
|
217
|
+
used by a model. It does not inspect values, aggregation/preprocessing code,
|
|
218
|
+
labels, train/test groups, semantic duplicates, model memory, or online serving.
|
|
219
|
+
A clean report is only agreement between the three supplied manifests and the
|
|
220
|
+
explicit two-clock selection policy.
|
|
221
|
+
|
|
222
|
+
Feast documents why filtering the created/known timestamp matters in addition to
|
|
223
|
+
event time: [point-in-time joins](https://docs.feast.dev/getting-started/concepts/point-in-time-joins).
|
|
224
|
+
Tools such as [Timefence](https://timefence.dev/api/audit/) cover timestamp audits
|
|
225
|
+
and rebuild-and-compare workflows. asofaudit is a narrower independent check of
|
|
226
|
+
**selected version identity and complete request-feature coverage** against a
|
|
227
|
+
separate version history. It does not replace those tools or claim new research.
|
|
228
|
+
|
|
229
|
+
## Develop
|
|
230
|
+
|
|
231
|
+
```sh
|
|
232
|
+
python -m pip install -e . coverage ruff build
|
|
233
|
+
python -m unittest discover -s tests -v
|
|
234
|
+
coverage run --branch --source=asofaudit -m unittest discover -s tests
|
|
235
|
+
coverage report -m
|
|
236
|
+
ruff check src tests
|
|
237
|
+
ruff format --check src tests
|
|
238
|
+
python -m build
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Tests include an independent integer-day nested-loop oracle, late corrections,
|
|
242
|
+
wrong entity/feature and absent selections, exact age boundaries, UTC offsets,
|
|
243
|
+
invalid inputs, complete pair coverage, storage errors, cleanup, input-byte
|
|
244
|
+
preservation, and POSIX scratch modes. Linux local verification is separate from
|
|
245
|
+
hosted CI. No Windows, macOS, deployment, adoption, or real-production-data claims.
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
## Opt-in strict event boundary
|
|
249
|
+
|
|
250
|
+
Some backward as-of pipelines deliberately exclude events at the exact prediction
|
|
251
|
+
instant. [pandas documents this choice as `allow_exact_matches=False`](https://pandas.pydata.org/docs/reference/api/pandas.merge_asof.html).
|
|
252
|
+
To audit that event-time policy, add `--strict-event-before`, or call
|
|
253
|
+
`audit(..., strict_event_before=True)`. The default remains `False`.
|
|
254
|
+
|
|
255
|
+
This changes **only** event eligibility to `event_at < prediction_at`. Known time
|
|
256
|
+
remains inclusive: `known_at <= prediction_at`, including corrections learned at
|
|
257
|
+
the prediction instant. The maximum `(event_at, known_at)` choice, exact UTC
|
|
258
|
+
microseconds, complete coverage, input receipts and example order stay the same.
|
|
259
|
+
This is not a full pandas compatibility adapter or a strict known-time policy.
|
|
260
|
+
|
|
261
|
+
Global and per-feature age limits still use inclusive event age. With age zero
|
|
262
|
+
and strict event eligibility, no version is eligible. At age one microsecond,
|
|
263
|
+
an event exactly one microsecond earlier is eligible if already known.
|
|
264
|
+
The API option must be an actual boolean; `0`, `1`, strings and `None` are invalid.
|
|
265
|
+
|
|
266
|
+
The report's existing `policy.eligibility` string records `<` instead of `<=` for
|
|
267
|
+
the event clause. No extra report fields are added. Default-mode reports remain
|
|
268
|
+
unchanged. A selected version whose event equals prediction time has the new
|
|
269
|
+
mutually exclusive reason `event_at_prediction`, between `future_event` and
|
|
270
|
+
`not_yet_known` in the documented precedence, only in strict mode. UTC-equivalent
|
|
271
|
+
strings compare equal. Future events still use `future_event`.
|
|
272
|
+
|
|
273
|
+
Tests include 150 seeded histories in both boundary modes, checked against an
|
|
274
|
+
independent nested-loop integer-microsecond oracle with per-feature ages, exact
|
|
275
|
+
selection replay, equality/UTC boundaries, reason precedence and CLI behavior.
|
|
276
|
+
This is local synthetic verification, not real-data validation or adoption.
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# asofaudit
|
|
2
|
+
|
|
3
|
+
Check whether a training-data pipeline selected the feature versions that were
|
|
4
|
+
actually eligible at each prediction time, including late-arriving corrections.
|
|
5
|
+
No feature values, feature-store server, pandas, network access, or input code
|
|
6
|
+
execution are needed. Python 3.9+ with the standard-library `sqlite3` module.
|
|
7
|
+
|
|
8
|
+
This is a **version-selection audit**, not proof that a dataset is leakage-free.
|
|
9
|
+
It trusts your version history, identifiers, timestamps, and declared policy.
|
|
10
|
+
|
|
11
|
+
## A correction from the future
|
|
12
|
+
|
|
13
|
+
A customer's balance event happened January 1. The original version was known
|
|
14
|
+
that day. A correction was written January 10. Selecting the correction for a
|
|
15
|
+
January 2 prediction uses a version that was not yet known, even though its event
|
|
16
|
+
time is before the prediction. Selecting an older version after a newer eligible
|
|
17
|
+
event is another error that checking only `feature_time <= prediction_time` misses.
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
python -m pip install .
|
|
21
|
+
asofaudit examples/history.csv examples/requests.csv examples/selected.csv \
|
|
22
|
+
--feature balance --examples 5
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The example exits 1, with two violations: `not_yet_known` for `prediction-1` and
|
|
26
|
+
`not_latest` for `prediction-2`. The explicit empty selection for `prediction-3`
|
|
27
|
+
is correct because that entity has no eligible history. Replacing `selected.csv`
|
|
28
|
+
with `correct.csv` exits 0. This is source installation, not a PyPI release.
|
|
29
|
+
|
|
30
|
+
## Three explicit CSV manifests
|
|
31
|
+
|
|
32
|
+
| Input | Required columns |
|
|
33
|
+
|---|---|
|
|
34
|
+
| History | `version_id,entity_id,feature,event_at,known_at` |
|
|
35
|
+
| Requests | `request_id,entity_id,prediction_at` |
|
|
36
|
+
| Selections | `request_id,feature,version_id` |
|
|
37
|
+
|
|
38
|
+
- Headers must contain exactly these columns, in any order, without duplicates.
|
|
39
|
+
- UTF-8 or UTF-8 BOM, comma-delimited CSV with Python's strict CSV parser.
|
|
40
|
+
Quoted commas and multiline fields work. Ragged/blank data records are invalid.
|
|
41
|
+
This does not implement a separate complete CSV grammar validator.
|
|
42
|
+
- IDs and feature names are exact strings, without trimming or case folding.
|
|
43
|
+
`001` and `1` are different. Required fields cannot be blank/whitespace-only or
|
|
44
|
+
contain NUL. Only selection `version_id` may be empty, meaning no feature value.
|
|
45
|
+
There are no inferred null tokens: `NA` is an ordinary identifier.
|
|
46
|
+
- Version IDs are globally unique. Request IDs are unique. Each entity/feature
|
|
47
|
+
`(event_at, known_at)` pair must be unique after UTC normalization. Ambiguous
|
|
48
|
+
ties are invalid, even if they would not affect a requested prediction.
|
|
49
|
+
- Supply each desired feature with a repeated `--feature` option. Every request
|
|
50
|
+
must have **exactly one selection for every requested feature**, including an
|
|
51
|
+
empty version for no value. Missing rows are invalid, never silently skipped.
|
|
52
|
+
- Unknown selected version IDs, unknown requests, unrequested features, duplicate
|
|
53
|
+
selections, empty request files, and invalid history rows are input errors.
|
|
54
|
+
History may be empty. Extra history features/entities are allowed and validated.
|
|
55
|
+
|
|
56
|
+
Timestamps must have exactly the form `YYYY-MM-DDTHH:MM:SS[.ffffff](Z|+HH:MM|-HH:MM)`.
|
|
57
|
+
Fractions have 1-6 digits. Four-digit years 0001-9999, valid dates, seconds 00-59,
|
|
58
|
+
hours 00-23, and explicit offsets are required. No naive times, leap seconds,
|
|
59
|
+
24:00:00, timezone names, DST inference, or sub-microsecond rounding. All comparisons
|
|
60
|
+
use integer UTC microseconds, including dates before 1970. Fractional seconds
|
|
61
|
+
with 1-6 digits are padded exactly to microseconds on all supported Python
|
|
62
|
+
versions, including 3.9 and 3.10; no precision is rounded or truncated.
|
|
63
|
+
|
|
64
|
+
## Declared selection policy
|
|
65
|
+
|
|
66
|
+
For the request's exact entity and feature:
|
|
67
|
+
|
|
68
|
+
1. Keep versions with both `event_at <= prediction_at` and
|
|
69
|
+
`known_at <= prediction_at`. Equality is eligible.
|
|
70
|
+
2. With `--max-age-us N`, also require `prediction_at - event_at <= N`.
|
|
71
|
+
This is an inclusive, nonnegative **event-age** limit in microseconds, not an
|
|
72
|
+
ingestion-age limit. Omit it for no age limit.
|
|
73
|
+
3. Select the maximum `(event_at, known_at)` in that order. A newer eligible
|
|
74
|
+
event wins over a more recently learned correction to an older event.
|
|
75
|
+
4. If no version is eligible, expect an explicit empty selected version.
|
|
76
|
+
|
|
77
|
+
This policy is fixed, not inferred from the manifests. If your pipeline uses
|
|
78
|
+
strict known-before times, global snapshot cutoffs, aggregation windows, deletions,
|
|
79
|
+
priorities, or another tie-breaker, this model is not sufficient.
|
|
80
|
+
A version whose known time precedes its event time is permitted but still must
|
|
81
|
+
pass both eligibility comparisons.
|
|
82
|
+
|
|
83
|
+
### Different age limits for different features
|
|
84
|
+
|
|
85
|
+
Use `--feature-age-limits ages.json` instead of `--max-age-us` when features
|
|
86
|
+
have different declared freshness requirements:
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
{"balance": 86400000000, "plan": null}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
asofaudit history.csv requests.csv selected.csv \
|
|
94
|
+
--feature balance --feature plan --feature-age-limits ages.json --examples 5
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
A complete synthetic example is included:
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
asofaudit examples/feature-ages/history.csv examples/feature-ages/requests.csv \
|
|
101
|
+
examples/feature-ages/selected.csv --feature balance --feature plan \
|
|
102
|
+
--feature-age-limits examples/feature-ages/ages.json --examples 5
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
It exits 0: the two-day-old balance is explicitly absent and the equally old plan
|
|
106
|
+
is still eligible. Replacing `selected.csv` with `stale.csv` exits 1 with one
|
|
107
|
+
`expired` balance selection and an empty expected version.
|
|
108
|
+
|
|
109
|
+
This declares an inclusive one-day event-age limit for `balance` and explicitly
|
|
110
|
+
no age limit for `plan`. Both still require event and known times at or before
|
|
111
|
+
the prediction. It does not use the current clock or age since ingestion.
|
|
112
|
+
|
|
113
|
+
The JSON object must contain **exactly every requested feature**, with exact
|
|
114
|
+
names. No missing features, extras, defaults, or inheritance. Values are integer
|
|
115
|
+
microseconds from 0 through 315537897599999999, or `null` for unlimited. Booleans,
|
|
116
|
+
floats (including `1.0`), strings, negative or out-of-range values, duplicate
|
|
117
|
+
keys (including escaped aliases), and non-finite numbers are invalid. The file
|
|
118
|
+
must be UTF-8 (optional BOM), at most 1 MiB, and contain one JSON object. Invalid
|
|
119
|
+
policy or manifests exit 2 without a partial JSON report. The policy file is
|
|
120
|
+
read once and does not change the three CSV per-input byte/row limits.
|
|
121
|
+
|
|
122
|
+
The library equivalent is
|
|
123
|
+
`audit(..., features=['balance', 'plan'], feature_max_age_us={'balance': 86400000000, 'plan': None})`.
|
|
124
|
+
It copies the complete mapping before reading inputs. This mode cannot be
|
|
125
|
+
combined with a non-`None` global `max_age_us`. Omitting it preserves the existing
|
|
126
|
+
global/no-limit mode and report shape.
|
|
127
|
+
|
|
128
|
+
In this opt-in mode, schema-version-1 `policy` additionally contains the complete
|
|
129
|
+
normalized `feature_max_age_us` mapping; `max_age_us` is `null` because there is no
|
|
130
|
+
global limit. Consumers must read the per-feature mapping when present, not
|
|
131
|
+
interpret that global `null` as making every feature unlimited. The normalized
|
|
132
|
+
values are the policy used by the audit; the JSON file's raw bytes are not hashed
|
|
133
|
+
or added to the three CSV receipts. Keep the report if policy provenance matters.
|
|
134
|
+
This is explicit caller configuration, not an import of Feast feature-view TTLs
|
|
135
|
+
or a complete feature-store compatibility adapter.
|
|
136
|
+
|
|
137
|
+
A known selected version that violates the policy produces one reason, in this
|
|
138
|
+
precedence: `wrong_entity`, `wrong_feature`, `future_event`, `not_yet_known`,
|
|
139
|
+
`expired`, `not_latest`. An empty selection when a value exists is
|
|
140
|
+
`missing_selection`. The report lists the expected version only when examples
|
|
141
|
+
are requested. A wrong version can violate several rules; reason counts are
|
|
142
|
+
mutually exclusive, not a count of every possible defect.
|
|
143
|
+
|
|
144
|
+
## Reports and CI
|
|
145
|
+
|
|
146
|
+
```sh
|
|
147
|
+
asofaudit history.csv requests.csv selected.csv \
|
|
148
|
+
--feature balance --feature plan --max-age-us 604800000000 > audit.json
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
- Exit **0**: complete audit, every requested pair matches this policy.
|
|
152
|
+
- Exit **1**: complete audit, some pairs violate this policy. JSON remains complete.
|
|
153
|
+
- Exit **2**: invalid/incomplete inputs, bad options, resource limit, storage
|
|
154
|
+
error, or output I/O failure. Invalid input emits no JSON report on stdout.
|
|
155
|
+
Output failures cannot retract bytes already written to a failing pipe or
|
|
156
|
+
filesystem; those bytes are not a complete report. Diagnostics on stderr are
|
|
157
|
+
best effort if that destination also fails.
|
|
158
|
+
|
|
159
|
+
JSON schema version 1 includes counts, per-feature counts, mutually exclusive
|
|
160
|
+
reason counts, declared policy, and SHA256/byte/row counts of each input. Digests
|
|
161
|
+
bind the bytes actually read. They are not signatures, proof of history
|
|
162
|
+
completeness, or an atomic cross-file snapshot. Freeze the three manifests before
|
|
163
|
+
auditing; concurrent source edits are outside the guarantee.
|
|
164
|
+
|
|
165
|
+
Examples default to **0**. Use `--examples N` (0-1000) for bounded evidence in
|
|
166
|
+
request-ID order and then supplied feature order. Examples expose request IDs,
|
|
167
|
+
feature names, selected versions, and expected versions. Counts also disclose
|
|
168
|
+
feature names and dataset sizes. Treat reports as private when appropriate.
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
from asofaudit import audit
|
|
172
|
+
|
|
173
|
+
report = audit('history.csv', 'requests.csv', 'selected.csv',
|
|
174
|
+
features=['balance'], examples=0)
|
|
175
|
+
assert report['ok'] # Only the stated version-selection policy.
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Disk, limits, and privacy
|
|
179
|
+
|
|
180
|
+
Inputs are streamed into a new temporary SQLite database. There is no extraction,
|
|
181
|
+
network, telemetry, input modification, or automatic repair. Identifiers and
|
|
182
|
+
timestamps are written to disk in plaintext; feature values are never requested.
|
|
183
|
+
`--temp-dir DIR` selects an existing scratch parent. On POSIX, the new directory
|
|
184
|
+
is mode 0700 and database 0600. Windows permission equivalence is not claimed.
|
|
185
|
+
|
|
186
|
+
Normal completion and errors close/remove the database and scratch directory.
|
|
187
|
+
Removal is not secure erasure. Forced termination/power loss can leave files;
|
|
188
|
+
backups, filesystem snapshots and elevated access can expose them. Cleanup failure
|
|
189
|
+
is an error and may mask an earlier error. Choose scratch storage accordingly.
|
|
190
|
+
|
|
191
|
+
Limits default to 1,000,000 rows **per input**, 256 MiB bytes **per input**, and
|
|
192
|
+
1,000,000 request-feature pairs. Configure with `--max-rows`, `--max-bytes`, and
|
|
193
|
+
`--max-pairs`. Python's CSV field-size limit also applies. Crossing any limit fails
|
|
194
|
+
the whole audit. SQLite cache is advisory 8 MiB; this is not a hard RAM/disk/time
|
|
195
|
+
bound. SQLite indexes consume extra disk. Requests are evaluated internally in prediction-time order. Each history row
|
|
196
|
+
enters a partial lookup index only when its known time has arrived, avoiding
|
|
197
|
+
repeated scans over future corrections for every prediction. Bounded examples
|
|
198
|
+
still use request-ID order and supplied feature order, independent of evaluation
|
|
199
|
+
order. The database writes an eligibility flag and maintains an extra known-time
|
|
200
|
+
index; this can add disk/I/O cost on ordinary histories. No runtime bound or
|
|
201
|
+
large-scale performance claim is made.
|
|
202
|
+
|
|
203
|
+
## What this does not establish
|
|
204
|
+
|
|
205
|
+
The audit cannot prove that source timestamps are true, records are complete,
|
|
206
|
+
version IDs bind immutable payloads, or logged selections match the data actually
|
|
207
|
+
used by a model. It does not inspect values, aggregation/preprocessing code,
|
|
208
|
+
labels, train/test groups, semantic duplicates, model memory, or online serving.
|
|
209
|
+
A clean report is only agreement between the three supplied manifests and the
|
|
210
|
+
explicit two-clock selection policy.
|
|
211
|
+
|
|
212
|
+
Feast documents why filtering the created/known timestamp matters in addition to
|
|
213
|
+
event time: [point-in-time joins](https://docs.feast.dev/getting-started/concepts/point-in-time-joins).
|
|
214
|
+
Tools such as [Timefence](https://timefence.dev/api/audit/) cover timestamp audits
|
|
215
|
+
and rebuild-and-compare workflows. asofaudit is a narrower independent check of
|
|
216
|
+
**selected version identity and complete request-feature coverage** against a
|
|
217
|
+
separate version history. It does not replace those tools or claim new research.
|
|
218
|
+
|
|
219
|
+
## Develop
|
|
220
|
+
|
|
221
|
+
```sh
|
|
222
|
+
python -m pip install -e . coverage ruff build
|
|
223
|
+
python -m unittest discover -s tests -v
|
|
224
|
+
coverage run --branch --source=asofaudit -m unittest discover -s tests
|
|
225
|
+
coverage report -m
|
|
226
|
+
ruff check src tests
|
|
227
|
+
ruff format --check src tests
|
|
228
|
+
python -m build
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Tests include an independent integer-day nested-loop oracle, late corrections,
|
|
232
|
+
wrong entity/feature and absent selections, exact age boundaries, UTC offsets,
|
|
233
|
+
invalid inputs, complete pair coverage, storage errors, cleanup, input-byte
|
|
234
|
+
preservation, and POSIX scratch modes. Linux local verification is separate from
|
|
235
|
+
hosted CI. No Windows, macOS, deployment, adoption, or real-production-data claims.
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
## Opt-in strict event boundary
|
|
239
|
+
|
|
240
|
+
Some backward as-of pipelines deliberately exclude events at the exact prediction
|
|
241
|
+
instant. [pandas documents this choice as `allow_exact_matches=False`](https://pandas.pydata.org/docs/reference/api/pandas.merge_asof.html).
|
|
242
|
+
To audit that event-time policy, add `--strict-event-before`, or call
|
|
243
|
+
`audit(..., strict_event_before=True)`. The default remains `False`.
|
|
244
|
+
|
|
245
|
+
This changes **only** event eligibility to `event_at < prediction_at`. Known time
|
|
246
|
+
remains inclusive: `known_at <= prediction_at`, including corrections learned at
|
|
247
|
+
the prediction instant. The maximum `(event_at, known_at)` choice, exact UTC
|
|
248
|
+
microseconds, complete coverage, input receipts and example order stay the same.
|
|
249
|
+
This is not a full pandas compatibility adapter or a strict known-time policy.
|
|
250
|
+
|
|
251
|
+
Global and per-feature age limits still use inclusive event age. With age zero
|
|
252
|
+
and strict event eligibility, no version is eligible. At age one microsecond,
|
|
253
|
+
an event exactly one microsecond earlier is eligible if already known.
|
|
254
|
+
The API option must be an actual boolean; `0`, `1`, strings and `None` are invalid.
|
|
255
|
+
|
|
256
|
+
The report's existing `policy.eligibility` string records `<` instead of `<=` for
|
|
257
|
+
the event clause. No extra report fields are added. Default-mode reports remain
|
|
258
|
+
unchanged. A selected version whose event equals prediction time has the new
|
|
259
|
+
mutually exclusive reason `event_at_prediction`, between `future_event` and
|
|
260
|
+
`not_yet_known` in the documented precedence, only in strict mode. UTC-equivalent
|
|
261
|
+
strings compare equal. Future events still use `future_event`.
|
|
262
|
+
|
|
263
|
+
Tests include 150 seeded histories in both boundary modes, checked against an
|
|
264
|
+
independent nested-loop integer-microsecond oracle with per-feature ages, exact
|
|
265
|
+
selection replay, equality/UTC boundaries, reason precedence and CLI behavior.
|
|
266
|
+
This is local synthetic verification, not real-data validation or adoption.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"balance": 86400000000, "plan": null}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
version_id,entity_id,feature,event_at,known_at
|
|
2
|
+
balance-v1,customer-1,balance,2024-01-01T00:00:00Z,2024-01-01T01:00:00Z
|
|
3
|
+
balance-corrected,customer-1,balance,2024-01-01T00:00:00Z,2024-01-10T01:00:00Z
|
|
4
|
+
balance-v2,customer-1,balance,2024-01-03T00:00:00Z,2024-01-03T01:00:00Z
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "asofaudit"
|
|
7
|
+
version = "0.4.0"
|
|
8
|
+
description = "Offline bitemporal feature-selection audit against explicit version histories"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
|
|
13
|
+
[project.scripts]
|
|
14
|
+
asofaudit = "asofaudit.cli:cli"
|
|
15
|
+
|
|
16
|
+
[tool.setuptools.packages.find]
|
|
17
|
+
where = ["src"]
|
|
18
|
+
|
|
19
|
+
[tool.ruff]
|
|
20
|
+
line-length = 88
|
|
21
|
+
|
|
22
|
+
[tool.ruff.lint]
|
|
23
|
+
select = ["E4", "E7", "E9", "F", "I"]
|