llmvalidate 1.1.0__tar.gz → 1.2.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.
- {llmvalidate-1.1.0/src/llmvalidate.egg-info → llmvalidate-1.2.0}/PKG-INFO +1 -1
- {llmvalidate-1.1.0 → llmvalidate-1.2.0}/pyproject.toml +1 -1
- {llmvalidate-1.1.0 → llmvalidate-1.2.0}/src/llmvalidate/__init__.py +13 -2
- {llmvalidate-1.1.0 → llmvalidate-1.2.0}/src/llmvalidate/cells.py +78 -0
- {llmvalidate-1.1.0 → llmvalidate-1.2.0}/src/llmvalidate/sortable_date.py +9 -0
- {llmvalidate-1.1.0 → llmvalidate-1.2.0/src/llmvalidate.egg-info}/PKG-INFO +1 -1
- {llmvalidate-1.1.0 → llmvalidate-1.2.0}/LICENSE +0 -0
- {llmvalidate-1.1.0 → llmvalidate-1.2.0}/readme.md +0 -0
- {llmvalidate-1.1.0 → llmvalidate-1.2.0}/setup.cfg +0 -0
- {llmvalidate-1.1.0 → llmvalidate-1.2.0}/src/llmvalidate/structured.py +0 -0
- {llmvalidate-1.1.0 → llmvalidate-1.2.0}/src/llmvalidate/utils.py +0 -0
- {llmvalidate-1.1.0 → llmvalidate-1.2.0}/src/llmvalidate/validation.py +0 -0
- {llmvalidate-1.1.0 → llmvalidate-1.2.0}/src/llmvalidate.egg-info/SOURCES.txt +0 -0
- {llmvalidate-1.1.0 → llmvalidate-1.2.0}/src/llmvalidate.egg-info/dependency_links.txt +0 -0
- {llmvalidate-1.1.0 → llmvalidate-1.2.0}/src/llmvalidate.egg-info/requires.txt +0 -0
- {llmvalidate-1.1.0 → llmvalidate-1.2.0}/src/llmvalidate.egg-info/top_level.txt +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Managed by python-semantic-release — do not edit by hand; the release workflow rewrites
|
|
2
2
|
# this line. Set to 0.7.0 once by hand to clear the drift from ONC-12379, during which the
|
|
3
3
|
# release never reached this file and it stayed at 0.0.0 across every published version.
|
|
4
|
-
__version__ = "1.
|
|
4
|
+
__version__ = "1.2.0"
|
|
5
5
|
|
|
6
6
|
# `structured` is pydantic-only and cheap, so it is imported eagerly: consumers that
|
|
7
7
|
# only need the extraction contract (StructuredResult / StructuredField) get it without
|
|
@@ -10,7 +10,13 @@ from .structured import StructuredResult, StructuredGroup, StructuredField
|
|
|
10
10
|
|
|
11
11
|
# `sortable_date` is std-lib only (`re`, `datetime`), so it is likewise eager: normalising a
|
|
12
12
|
# date string must not cost the caller a pandas import. Keep it dependency-free.
|
|
13
|
-
from .sortable_date import
|
|
13
|
+
from .sortable_date import (
|
|
14
|
+
DATE_MASKS,
|
|
15
|
+
is_canonical_date,
|
|
16
|
+
is_date_mask,
|
|
17
|
+
to_canonical_date,
|
|
18
|
+
to_sortable_date,
|
|
19
|
+
)
|
|
14
20
|
|
|
15
21
|
# `cells` states the value-level conventions of a scored table — the no-finding sentinel,
|
|
16
22
|
# list cells, and the `-value`/`-code` facet columns. Std-lib only for the same reason:
|
|
@@ -20,8 +26,10 @@ from .cells import (
|
|
|
20
26
|
FACET_SUFFIXES,
|
|
21
27
|
NO_FINDING,
|
|
22
28
|
VALUE_SUFFIX,
|
|
29
|
+
canonical_date_cell,
|
|
23
30
|
facet_columns,
|
|
24
31
|
format_list_cell,
|
|
32
|
+
is_canonical_date_cell,
|
|
25
33
|
is_no_finding,
|
|
26
34
|
is_unlabelled,
|
|
27
35
|
parse_list_cell,
|
|
@@ -38,7 +46,10 @@ __all__ = [
|
|
|
38
46
|
"to_sortable_date",
|
|
39
47
|
"to_canonical_date",
|
|
40
48
|
"is_canonical_date",
|
|
49
|
+
"is_date_mask",
|
|
41
50
|
"DATE_MASKS",
|
|
51
|
+
"canonical_date_cell",
|
|
52
|
+
"is_canonical_date_cell",
|
|
42
53
|
# cell conventions
|
|
43
54
|
"NO_FINDING",
|
|
44
55
|
"is_no_finding",
|
|
@@ -20,6 +20,10 @@ them once:
|
|
|
20
20
|
* **Facet columns.** A field carrying a `code` flattens to two scored columns, `<field>-value`
|
|
21
21
|
and `<field>-code` (see `utils.flatten_structured_result`). `facet_columns` builds the pair
|
|
22
22
|
and `split_facet` takes it apart.
|
|
23
|
+
* **Date cells.** A column defined to hold a date holds one canonical rendering of one — and
|
|
24
|
+
the sentinels. `canonical_date_cell` / `is_canonical_date_cell` are the two conventions
|
|
25
|
+
together: `sortable_date`'s mask rules for a real value, and the rules above for a cell
|
|
26
|
+
that says nothing or says "nothing to find".
|
|
23
27
|
|
|
24
28
|
Std-lib only, and eagerly importable: reading or writing a cell must not cost the caller a
|
|
25
29
|
pandas import.
|
|
@@ -40,6 +44,8 @@ import math
|
|
|
40
44
|
from ast import literal_eval
|
|
41
45
|
from typing import Any
|
|
42
46
|
|
|
47
|
+
from .sortable_date import _precision, is_canonical_date, to_canonical_date
|
|
48
|
+
|
|
43
49
|
# The "no information" sentinel: the source was read and stated nothing to find. A real,
|
|
44
50
|
# graded answer — not the absence of one.
|
|
45
51
|
NO_FINDING = "-"
|
|
@@ -202,3 +208,75 @@ def split_facet(column: str) -> tuple[str, str | None]:
|
|
|
202
208
|
if column.endswith(suffix) and len(column) > len(suffix):
|
|
203
209
|
return column[: -len(suffix)], suffix.lstrip("-")
|
|
204
210
|
return column, None
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
# --- Date cells ---------------------------------------------------------------
|
|
214
|
+
|
|
215
|
+
def canonical_date_cell(cell: Any, mask: str = "YYYY-MM-DD", dayFirst: bool = True) -> Any:
|
|
216
|
+
"""`cell`'s canonical date at `mask`, with the sentinels preserved.
|
|
217
|
+
|
|
218
|
+
The cell-level counterpart to `sortable_date.to_canonical_date`, which returns None for
|
|
219
|
+
"no usable date" precisely so a caller can decide what that means in a *cell*. Here:
|
|
220
|
+
|
|
221
|
+
* an **unlabelled** cell (empty, NaN, `pd.NA`) is returned unchanged — it says nothing
|
|
222
|
+
about the field, and turning that into an answer would put an out-of-scope row into a
|
|
223
|
+
scorer's denominator;
|
|
224
|
+
* the **no-finding** cell `"-"` stays `NO_FINDING`;
|
|
225
|
+
* other text is rendered at the mask (see `to_canonical_date` for the rules: the mask
|
|
226
|
+
truncates but never pads, a time is dropped, a year-less date is not a date), and text
|
|
227
|
+
holding **no readable date** becomes `NO_FINDING` — the honest reading of "we looked
|
|
228
|
+
and there is nothing here";
|
|
229
|
+
* anything that is **neither text nor a missing marker** — a list, a number, a `date`
|
|
230
|
+
object — is returned **unchanged**. It is not a date cell at all, so manufacturing a
|
|
231
|
+
sentinel for it would hide a wrong-column-type bug behind a plausible-looking answer.
|
|
232
|
+
`is_canonical_date_cell` rejects it, which is where such a cell should surface. Note
|
|
233
|
+
`[]` lands here: the empty list is the no-finding sentinel of a **list** column, not of
|
|
234
|
+
a date one.
|
|
235
|
+
|
|
236
|
+
For text and for missing markers — everything a cell in such a column should ever hold —
|
|
237
|
+
whatever this returns satisfies `is_canonical_date_cell` for the same `(mask, dayFirst)`,
|
|
238
|
+
so a producer can put dirty text straight through it.
|
|
239
|
+
|
|
240
|
+
An unknown `mask` raises `ValueError`, checked **before** the cell — as in
|
|
241
|
+
`to_canonical_date`. A misspelled column type has to be reported by the first cell it is
|
|
242
|
+
used on, not only by the first cell that happens to carry a date.
|
|
243
|
+
|
|
244
|
+
One caution for **label** builders: text holding no readable date is indistinguishable
|
|
245
|
+
here from a cell that recorded nothing, since both come back as `NO_FINDING`. Compare the
|
|
246
|
+
result against what the source was meant to say and fail the build when they disagree —
|
|
247
|
+
silently mislabelling a row is worse than not building.
|
|
248
|
+
"""
|
|
249
|
+
_precision(mask) # a bad mask is a bad mask, whatever this cell holds
|
|
250
|
+
if is_unlabelled(cell):
|
|
251
|
+
return cell
|
|
252
|
+
if not isinstance(cell, str):
|
|
253
|
+
return cell # not text, not missing: not a date cell — leave it visible
|
|
254
|
+
if is_no_finding(cell):
|
|
255
|
+
return NO_FINDING
|
|
256
|
+
rendered = to_canonical_date(cell, mask, dayFirst=dayFirst)
|
|
257
|
+
return rendered if rendered is not None else NO_FINDING
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def is_canonical_date_cell(cell: Any, mask: str = "YYYY-MM-DD", dayFirst: bool = True) -> bool:
|
|
261
|
+
"""True when a column defined to hold a `mask` date may hold `cell` as it stands.
|
|
262
|
+
|
|
263
|
+
That is: an unlabelled cell, the `"-"` sentinel, or a canonical date at the mask's
|
|
264
|
+
precision **or coarser** (`is_canonical_date`). A test of *cleanliness*, not of
|
|
265
|
+
correctness: a coarser value is clean and will simply score wrong against a finer label.
|
|
266
|
+
Finer than the mask is not clean, and neither is anything `dayFirst` cannot read.
|
|
267
|
+
|
|
268
|
+
A cell that is not text is not a date cell — a list, a number, a `date` object all fail
|
|
269
|
+
here, so a column carrying the wrong sort of cell shows up in validation instead of
|
|
270
|
+
passing as something else. `[]` in particular: it is the no-finding sentinel of a
|
|
271
|
+
**list** column, and this is not one.
|
|
272
|
+
|
|
273
|
+
An unknown `mask` raises `ValueError` rather than answering, checked **before** the cell:
|
|
274
|
+
a validator sweeping a column must not report a malformed schema as clean just because
|
|
275
|
+
the rows it reached were sentinels.
|
|
276
|
+
"""
|
|
277
|
+
_precision(mask) # as in `is_canonical_date`: value-independent
|
|
278
|
+
if is_unlabelled(cell):
|
|
279
|
+
return True
|
|
280
|
+
if not isinstance(cell, str):
|
|
281
|
+
return False
|
|
282
|
+
return is_no_finding(cell) or is_canonical_date(cell, mask, dayFirst=dayFirst)
|
|
@@ -487,6 +487,15 @@ DATE_MASKS = {"YYYY-MM-DD": 3, "YYYY-MM": 2, "YYYY": 1}
|
|
|
487
487
|
_CANONICAL_DATE_RE = re.compile(r"^\d{4}(-\d{2}){0,2}$")
|
|
488
488
|
|
|
489
489
|
|
|
490
|
+
def is_date_mask(value: Any) -> bool:
|
|
491
|
+
"""True when `value` names one of the masks in `DATE_MASKS`.
|
|
492
|
+
|
|
493
|
+
For a caller whose schema declares a column's type as a string: this is the test for
|
|
494
|
+
"does this column hold a date", without it having to hard-code the mask names.
|
|
495
|
+
"""
|
|
496
|
+
return isinstance(value, str) and value in DATE_MASKS
|
|
497
|
+
|
|
498
|
+
|
|
490
499
|
def _precision(mask: str) -> int:
|
|
491
500
|
"""How many components `mask` keeps. Raises `ValueError` for a mask that isn't one."""
|
|
492
501
|
try:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|