Skip to content

Commit

Permalink
Merge pull request #44 from condekind/bump/polars_1.3.0
Browse files Browse the repository at this point in the history
Bump python-polars to >=1.3.0
  • Loading branch information
MarcoGorelli authored Aug 19, 2024
2 parents 26a8620 + cba8d80 commit 86bea37
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 147 deletions.
107 changes: 55 additions & 52 deletions minimal_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,154 +3,157 @@

import polars as pl
from pathlib import Path
from minimal_plugin.utils import register_plugin, parse_version

if parse_version(pl.__version__) < parse_version("0.20.16"):
from polars.utils.udfs import _get_shared_lib_location # type: ignore[missing-import]
from polars.plugins import register_plugin_function

lib: str | Path = _get_shared_lib_location(__file__)
else:
lib = Path(__file__).parent

LIB = Path(__file__).parent

if TYPE_CHECKING:
from minimal_plugin.typing import IntoExpr


def noop(expr: IntoExpr) -> pl.Expr:
return register_plugin(
return register_plugin_function(
args=[expr],
lib=lib,
symbol="noop",
plugin_path=LIB,
function_name="noop",
is_elementwise=True,
)


def abs_i64(expr: IntoExpr) -> pl.Expr:
return register_plugin(
return register_plugin_function(
args=[expr],
lib=lib,
symbol="abs_i64",
plugin_path=LIB,
function_name="abs_i64",
is_elementwise=True,
)


def abs_numeric(expr: IntoExpr) -> pl.Expr:
return register_plugin(
return register_plugin_function(
args=[expr],
lib=lib,
symbol="abs_numeric",
plugin_path=LIB,
function_name="abs_numeric",
is_elementwise=True,
)


def sum_i64(expr: IntoExpr, other: IntoExpr) -> pl.Expr:
return register_plugin(
return register_plugin_function(
args=[expr, other],
lib=lib,
symbol="sum_i64",
plugin_path=LIB,
function_name="sum_i64",
is_elementwise=True,
)


def cum_sum(expr: IntoExpr) -> pl.Expr:
return register_plugin(
return register_plugin_function(
args=[expr],
lib=lib,
symbol="cum_sum",
plugin_path=LIB,
function_name="cum_sum",
is_elementwise=False,
)


def pig_latinnify(expr: IntoExpr) -> pl.Expr:
return register_plugin(
return register_plugin_function(
args=[expr],
lib=lib,
symbol="pig_latinnify",
plugin_path=LIB,
function_name="pig_latinnify",
is_elementwise=True,
)


def abs_i64_fast(expr: IntoExpr) -> pl.Expr:
return register_plugin(
return register_plugin_function(
args=[expr],
lib=lib,
symbol="abs_i64_fast",
plugin_path=LIB,
function_name="abs_i64_fast",
is_elementwise=True,
)


def add_suffix(expr: IntoExpr, *, suffix: str) -> pl.Expr:
return register_plugin(
return register_plugin_function(
args=[expr],
lib=lib,
symbol="add_suffix",
plugin_path=LIB,
function_name="add_suffix",
is_elementwise=True,
kwargs={"suffix": suffix},
)


def snowball_stem(expr: IntoExpr) -> pl.Expr:
return register_plugin(
return register_plugin_function(
args=[expr],
lib=lib,
symbol="snowball_stem",
plugin_path=LIB,
function_name="snowball_stem",
is_elementwise=True,
)


def weighted_mean(expr: IntoExpr, weights: IntoExpr) -> pl.Expr:
return register_plugin(
return register_plugin_function(
args=[expr, weights],
lib=lib,
symbol="weighted_mean",
plugin_path=LIB,
function_name="weighted_mean",
is_elementwise=True,
)


def shift_struct(expr: IntoExpr) -> pl.Expr:
return register_plugin(
return register_plugin_function(
args=[expr],
lib=lib,
symbol="shift_struct",
plugin_path=LIB,
function_name="shift_struct",
is_elementwise=True,
)


def reverse_geocode(lat: IntoExpr, long: IntoExpr) -> pl.Expr:
return register_plugin(
args=[lat, long], lib=lib, symbol="reverse_geocode", is_elementwise=True
return register_plugin_function(
args=[lat, long],
plugin_path=LIB,
function_name="reverse_geocode",
is_elementwise=True,
)


def non_zero_indices(expr: IntoExpr) -> pl.Expr:
return register_plugin(
args=[expr], lib=lib, symbol="non_zero_indices", is_elementwise=True
return register_plugin_function(
args=[expr],
plugin_path=LIB,
function_name="non_zero_indices",
is_elementwise=True,
)


def vertical_weighted_mean(values: IntoExpr, weights: IntoExpr) -> pl.Expr:
return register_plugin(
return register_plugin_function(
args=[values, weights],
lib=lib,
symbol="vertical_weighted_mean",
plugin_path=LIB,
function_name="vertical_weighted_mean",
is_elementwise=False,
returns_scalar=True,
)


def interpolate(expr: IntoExpr) -> pl.Expr:
return register_plugin(
return register_plugin_function(
args=[expr],
lib=lib,
symbol="interpolate",
plugin_path=LIB,
function_name="interpolate",
is_elementwise=False,
)


def life_step(left: IntoExpr, mid: IntoExpr, right: IntoExpr) -> pl.Expr:
return register_plugin(
return register_plugin_function(
args=[left, mid, right],
lib=lib,
symbol="life_step",
plugin_path=LIB,
function_name="life_step",
is_elementwise=False,
)
90 changes: 0 additions & 90 deletions minimal_plugin/utils.py

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["maturin>=1.0,<2.0", "polars>=0.26.0"]
requires = ["maturin>=1.0,<2.0", "polars>=1.3.0"]
build-backend = "maturin"

[project]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
maturin>=1.4.0
polars>=0.20.6
polars>=1.3.0
5 changes: 2 additions & 3 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import polars as pl
import minimal_plugin as mp


import polars as pl
import minimal_plugin as mp


df = pl.DataFrame(
{"values": [[1, 3, 2], [5, 7], []], "weights": [[0.5, 0.3, 0.2], [0.1, 0.9], []]}
)
Expand Down Expand Up @@ -37,3 +35,4 @@
)
result = df.with_columns(interpolate=mp.interpolate("a"))
print(result)

0 comments on commit 86bea37

Please sign in to comment.