typedecide.data.loaders¶
Reading decisions from JSONL, JSON, CSV/TSV, Parquet and Hugging Face datasets. Task-oriented walkthrough: Bring your own data.
typedecide.data.loaders
¶
Reading decisions out of whatever the customer already has.
This is the first surface a new user touches, and the data they bring is a CSV a ticketing system exported at four in the afternoon. So every failure here names the row, names the column, quotes the offending value and says what would fix it. A loader that says "invalid input" has made the library someone else's problem.
SUFFIX_FORMATS
module-attribute
¶
SUFFIX_FORMATS: dict[str, str] = {
".jsonl": "jsonl",
".ndjson": "jsonl",
".json": "json",
".csv": "csv",
".tsv": "csv",
".parquet": "parquet",
".pq": "parquet",
}
OPTION_DELIMITERS
module-attribute
¶
FieldMapping
dataclass
¶
FieldMapping(
state: str = "state",
question: str = "question",
options: str = "options",
answer: str = "answer_id",
group: str | None = None,
id: str | None = None,
option_ids: str = "option_ids",
key: str = "key",
option_delimiter: str | None = None,
)
Maps a customer's column names onto our schema, so bring-your-own-data does not mean rename-your-columns-first.
The first six fields are the contract. The rest exist because CSV has to express a
set of options in a flat table, and there is no one spelling of that. group and
id default to None, which means "use the conventional column if the file
happens to have one, otherwise leave it unset".
load_decisions
¶
load_decisions(
source: str | Path,
*,
format: str | None = None,
mapping: FieldMapping | None = None
) -> list[Decision]
Load decisions from a file or a Hugging Face dataset id.
format is inferred from the suffix when not given: .jsonl/.ndjson,
.json, .csv/.tsv, .parquet/.pq. A string that is not an
existing path and looks like owner/name is read as a HF dataset id.
Source code in src/typedecide/data/loaders.py
write_decisions
¶
write_decisions(
decisions: Sequence[Decision], path: Path
) -> None
Write decisions back out. .json gets an array, anything else gets JSONL.