Skip to content

Commit 3b2ef21

Browse files
authored
Merge pull request #13 from Point72/feat/synthetic-data-generators
Add scan_synthetic_panel and scan_synthetic_regression
2 parents e1fe60e + 0b620d4 commit 3b2ef21

4 files changed

Lines changed: 814 additions & 0 deletions

File tree

docs/wiki/API-Reference.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,35 @@ Convert a Narwhals `DataFrame` or `LazyFrame` (wrapping pandas, Dask, DuckDB, Py
204204
etc.) into the equivalent Polars object; lazy inputs are backed by a custom source so
205205
filters bridge to the underlying engine.
206206

207+
### `scan_synthetic_regression`
208+
209+
```python
210+
scan_synthetic_regression(*, n_samples, n_features, n_responses=1, use_weights=False,
211+
weights_low=0.5, weights_high=1.5, betas=None, epsilon_loc=0.0,
212+
epsilon_scale=1.0, chunk_key=None, n_chunks=None, seed=None,
213+
fetch_size=10_000) -> pl.LazyFrame
214+
```
215+
216+
Lazy source of synthetic linear-regression data `Y = X @ B + E` with Gaussian noise.
217+
Emits `x0..x{n_features-1}` and `y0..y{n_responses-1}`; with `use_weights=True` a `weight`
218+
column is added and noise is scaled so a WLS fit recovers `betas`. Row values are
219+
batch-independent for a fixed `seed`, and predicate/projection/`head` pushdowns apply.
220+
221+
### `scan_synthetic_panel`
222+
223+
```python
224+
scan_synthetic_panel(*, start_date, end_date, freq="1D", n_symbols=1, n_features,
225+
n_responses=1, betas=None, use_weights=False, weights_low=0.5,
226+
weights_high=1.5, categories=None, group_by=None, epsilon_loc=0.0,
227+
epsilon_scale=1.0, seed=None, fetch_size=10_000) -> pl.LazyFrame
228+
```
229+
230+
Lazy source of synthetic panel data on a `(date, symbol)` grid, one row per pair over the
231+
business days in `[start_date, end_date]`. Same regression model as
232+
`scan_synthetic_regression`, plus optional decorative `categories` and per-group
233+
coefficients via `group_by=(name, values)`. Rows are yielded date-by-date so
234+
`.set_sorted("date").group_by("date")` streams cleanly.
235+
207236
## Writing sinks
208237

209238
### `sink_delta` (function)

polars_io_tools/io_sources/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from .lazy_cache_parquet import *
1313
from .lazy_clickhouse_reader import *
1414
from .lazy_clickhouse_writer import *
15+
from .lazy_data_generator import *
1516
from .lazy_datadog_reader import *
1617
from .lazy_debug import debug, debug as _lazy_debug
1718
from .lazy_iter_rows import *
@@ -34,6 +35,7 @@
3435
from .join import filtered_join, filtered_join_asof # noqa: TC004
3536
from .lazy_clickhouse_reader import scan_clickhouse
3637
from .lazy_clickhouse_writer import sink_clickhouse # noqa: TC004
38+
from .lazy_data_generator import scan_synthetic_panel, scan_synthetic_regression
3739
from .lazy_iter_rows import iter_rows # noqa: TC004
3840
from .multi_source import FilterSpec, multi_source
3941
from .pushdown_pivot import pushdown_pivot

0 commit comments

Comments
 (0)