## aggregate.read_ylt()


Reads a year loss table from a CSV or Parquet file into years of


Usage

``` python
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](pricing.Portfolio.md#prospicio.pricing.Portfolio.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](aggregate.EventSet.md#prospicio.aggregate.EventSet.from_ylt) describes. The file's bytes are hashed ([ylt_hash](aggregate.ylt_hash.md#prospicio.aggregate.ylt_hash)) into the events' [input_hash](models.GlmFit.md#prospicio.models.GlmFit.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 - like`  

`year: str = ``"year", `<span class="st">`"value"`</span>  
The columns of each row's year, from 1, and its loss.

`loss: str = ``"year", `<span class="st">`"value"`</span>  
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 `None` to 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](aggregate.EventSet.md#prospicio.aggregate.EventSet.has_times)), for an hours clause ([EventSet.grouped](aggregate.EventSet.md#prospicio.aggregate.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 without `hour`); 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 without `hour`); 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](reinsurance.Tower.md#prospicio.reinsurance.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 `.parquet` or `.pq` file and CSV otherwise. Parquet needs `pyarrow`.

`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

``` python
>>> 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'\]})

``` python
>>> e.input_hash.startswith("blake3:")
```

True

``` python
>>> _ = 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)
