aggregate.read_ylt()
Reads a year loss table from a CSV or Parquet file into years of
Usage
aggregate.read_ylt(
path,
*,
year="year",
loss="value",
slot="slot",
time=None,
day=None,
hour=None,
labels=None,
n_years=None,
n_sims=None,
expand="tile",
seed=0,
unique_by=None,
expected=None,
file_format=None,
losses_negative=False
)events, checked and expanded to a run’s simulations.
The file has one row per non-zero event loss. Its rows are checked (losses finite and non-negative, years from 1, no repeated year and slot within the unique_by labels, labels among the expected values, times within the year), ordered by year, then time of loss when given, then slot (the file’s order breaking ties), and expanded as EventSet.from_ylt describes. The file’s bytes are hashed (ylt_hash) into the events’ input_hash, which results keep in their provenance. Rows sharing a slot, one event hitting several classes, stay separate losses.
Parameters
path: str or path - likeyear: str = "year", "value"-
The columns of each row’s year, from 1, and its loss.
loss: str = "year", "value"-
The columns of each row’s year, from 1, and its loss.
slot: str or None = "slot"-
The column of each row’s event slot, or
Noneto keep the file’s order within a year and skip the check for repeats. time: str = None-
The column of each row’s time of loss, the fraction of its year elapsed, in
[0, 1]. The events then carry times (has_times), for an hours clause (EventSet.grouped) and reinstatements pro rata as to time. day: str = None-
Instead of
time: the columns of each row’s day of the year, from 1 to 365, and hour of the day, from 0 to 24 (the start of the day withouthour); the time is((day - 1) * 24 + hour) / 8760, on the 8,760-hour year of the hours clause. hour: str = None-
Instead of
time: the columns of each row’s day of the year, from 1 to 365, and hour of the day, from 0 to 24 (the start of the day withouthour); the time is((day - 1) * 24 + hour) / 8760, on the 8,760-hour year of the hours clause. labels: list of str = None-
Columns kept as labels,
["peril", "class"]say, by which Tower.apply splits its results. n_years: int = None-
The table’s years, at least its largest year; by default the largest year.
n_sims: int = None-
The simulations to expand to, by default
n_years. expand: (tile, resample) = "tile"seed: int = 0-
The seed of
"resample". unique_by: list of str = None-
With slots, no two rows may share a year, a slot and their values in these labels (
["peril"]); by default every label. expected: dict of str to list of str = None-
The values allowed in each named label (
{"peril": ["WS", "EQ"]}). file_format: (csv, parquet) = "csv"-
By default Parquet for a
.parquetor.pqfile and CSV otherwise. Parquet needspyarrow. losses_negative: bool = False- The file stores losses as negative numbers, money going out, as some vendor and cedent files do: each must be at most 0 and is read with its sign flipped. Without it a negative loss is an error.
Returns
EventSet
Examples
>>> import os, tempfile
>>> from prospicio.aggregate import read_ylt
>>> path = os.path.join(tempfile.mkdtemp(), "ylt.csv")
>>> _ = open(path, "w").write("year,peril,slot,value\n2,wind,9,5\n1,quake,1,1\n2,wind,3,7\n")
>>> e = read_ylt(path, labels=["peril"], n_sims=4)
>>> e.events(1), e.labels(1)([7.0, 5.0], {‘peril’: [‘wind’, ‘wind’]})
>>> e.input_hash.startswith("blake3:")True
>>> _ = open(path, "w").write("year,day,hour,value\n1,200,6,5\n1,199,12,1\n")
>>> t = read_ylt(path, slot=None, day="day", hour="hour")
>>> t.events(0), t.has_times([1.0, 5.0], True)