Skip to content

Commit 9addae4

Browse files
committed
use io_plugin example instead
1 parent 05322fe commit 9addae4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+9696
-671
lines changed

2025/polars_bigquery_gcloud_bigquery/Cargo.lock

Lines changed: 1449 additions & 266 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

2025/polars_bigquery_gcloud_bigquery/Cargo.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ name = "polars_bigquery_gcloud_bigquery"
88
crate-type= ["cdylib"]
99

1010
[dependencies]
11-
pyo3 = { version = "0.23.0", features = ["extension-module", "abi3-py39"] }
12-
pyo3-polars = { version = "0.20.0", features = ["derive"] }
13-
serde = { version = "1", features = ["derive"] }
14-
polars = { version = "0.46.0", default-features = false }
15-
polars-arrow = { version = "0.46.0", default-features = false }
16-
11+
polars = { version = "0.49.1", features = ["fmt", "dtype-date", "timezones", "lazy"], default-features = false }
12+
polars-arrow = { version = "0.49.1", default-features = false }
13+
pyo3 = { version = "0.25", features = ["abi3-py39"] }
14+
pyo3-polars = { version = "0.22.0", features = ["derive", "lazy"] }
15+
rand = { version = "0.8.5", features = [] }

2025/polars_bigquery_gcloud_bigquery/Makefile

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
1-
from __future__ import annotations
2-
3-
from pathlib import Path
4-
from typing import TYPE_CHECKING
5-
1+
from .polars_bigquery_gcloud_bigquery import new_bernoulli, new_uniform, RandomSource
2+
from typing import Any, Iterator
3+
from polars.io.plugins import register_io_source
64
import polars as pl
7-
from polars.plugins import register_plugin_function
8-
9-
from polars_bigquery_gcloud_bigquery._internal import __version__ as __version__
10-
11-
if TYPE_CHECKING:
12-
from polars_bigquery_gcloud_bigquery.typing import IntoExprColumn
13-
14-
LIB = Path(__file__).parent
15-
165

17-
def pig_latinnify(expr: IntoExprColumn) -> pl.Expr:
18-
return register_plugin_function(
19-
args=[expr],
20-
plugin_path=LIB,
21-
function_name="pig_latinnify",
22-
is_elementwise=True,
23-
)
246

7+
def scan_random(samplers: list[Any], size: int = 1000) -> pl.LazyFrame:
8+
def source_generator(
9+
with_columns: list[str] | None,
10+
predicate: pl.Expr | None,
11+
n_rows: int | None,
12+
batch_size: int | None,
13+
) -> Iterator[pl.DataFrame]:
14+
"""
15+
Generator function that creates the source.
16+
This function will be registered as IO source.
17+
"""
18+
19+
new_size = size
20+
if n_rows is not None and n_rows < size:
21+
new_size = n_rows
22+
23+
src = RandomSource(samplers, batch_size, new_size)
24+
if with_columns is not None:
25+
src.set_with_columns(with_columns)
26+
27+
# Set the predicate.
28+
predicate_set = True
29+
if predicate is not None:
30+
try:
31+
src.try_set_predicate(predicate)
32+
except pl.exceptions.ComputeError:
33+
predicate_set = False
34+
35+
while (out := src.next()) is not None:
36+
# If the source could not apply the predicate
37+
# (because it wasn't able to deserialize it), we do it here.
38+
if not predicate_set and predicate is not None:
39+
out = out.filter(predicate)
40+
41+
yield out
42+
43+
# create src again to compute the schema
44+
src = RandomSource(samplers, 0, 0)
45+
return register_io_source(io_source=source_generator, schema=src.schema())

2025/polars_bigquery_gcloud_bigquery/polars_bigquery_gcloud_bigquery/_internal.pyi

Lines changed: 0 additions & 1 deletion
This file was deleted.

2025/polars_bigquery_gcloud_bigquery/polars_bigquery_gcloud_bigquery/typing.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

2025/polars_bigquery_gcloud_bigquery/pyproject.toml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@ build-backend = "maturin"
44

55
[project]
66
name = "polars-bigquery-gcloud-bigquery"
7-
requires-python = ">=3.8"
7+
version = "0.0.1"
8+
requires-python = ">=3.10"
89
classifiers = [
910
"Programming Language :: Rust",
1011
"Programming Language :: Python :: Implementation :: CPython",
1112
"Programming Language :: Python :: Implementation :: PyPy",
1213
]
13-
dynamic = ["version"]
14-
15-
[tool.maturin]
16-
module-name = "polars_bigquery_gcloud_bigquery._internal"
17-
18-
[[tool.mypy.overrides]]
19-
module = "polars.utils.udfs"
20-
ignore_missing_imports = true

2025/polars_bigquery_gcloud_bigquery/run.py

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly"
2+
channel = "nightly-2025-05-21"
33

2025/polars_bigquery_gcloud_bigquery/src/expressions.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)