Skip to content

Commit

Permalink
comply with polars>=1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
georgypv committed Jul 18, 2024
1 parent 6928a81 commit bd69b14
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 70 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polars_coord_transforms"
version = "0.9.1"
version = "0.10.0"
edition = "2021"

[lib]
Expand Down
155 changes: 87 additions & 68 deletions polars_coord_transforms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from pathlib import Path
import polars as pl
from polars.utils.udfs import _get_shared_lib_location
from polars.plugins import register_plugin_function
from polars.type_aliases import PolarsDataType

from typing import Protocol, Iterable, cast


lib = _get_shared_lib_location(__file__)


@pl.api.register_expr_namespace("s2")
class S2NameSpace:
def __init__(self, expr: pl.Expr):
Expand All @@ -16,29 +14,36 @@ def __init__(self, expr: pl.Expr):
def lonlat_to_cellid(self, level: int = 30) -> pl.Expr:
if level < 1 or level > 30:
raise ValueError("`level` parameter must be between 1 and 30!")

return self._expr.register_plugin(
lib=lib,
symbol="lonlat_to_cellid",
is_elementwise=True,
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="lonlat_to_cellid",
args=self._expr,
kwargs={"level": level},
is_elementwise=True
)

def cellid_to_lonlat(self) -> pl.Expr:
return self._expr.register_plugin(
lib=lib, symbol="cellid_to_lonlat", is_elementwise=True
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="cellid_to_lonlat",
args=self._expr,
is_elementwise=True
)

def cell_contains_point(self, point: pl.Expr) -> pl.Expr:
return self._expr.register_plugin(
lib=lib, symbol="cell_contains_point", is_elementwise=True, args=[point]
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="cell_contains_point",
args=[self._expr, point],
is_elementwise=True
)

def cellid_to_vertices(self) -> pl.Expr:
return self._expr.register_plugin(
lib=lib,
symbol="cellid_to_vertices",
is_elementwise=True,
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="cellid_to_vertices",
args=self._expr,
is_elementwise=True
)


Expand All @@ -48,67 +53,78 @@ def __init__(self, expr: pl.Expr):
self._expr = expr

def map_to_ecef(self, rotation: pl.Expr, offset: pl.Expr) -> pl.Expr:
return self._expr.register_plugin(
lib=lib, symbol="map_to_ecef", is_elementwise=True, args=[rotation, offset]
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="map_to_ecef",
args=[self._expr, rotation, offset],
is_elementwise=True
)

def ecef_to_map(self, rotation: pl.Expr, offset: pl.Expr) -> pl.Expr:
return self._expr.register_plugin(
lib=lib, symbol="ecef_to_map", is_elementwise=True, args=[rotation, offset]
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="ecef_to_map",
args=[self._expr, rotation, offset],
is_elementwise=True
)

def ecef_to_lla(self) -> pl.Expr:
return self._expr.register_plugin(
lib=lib,
symbol="ecef_to_lla",
is_elementwise=True,
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="ecef_to_lla",
args=self._expr,
is_elementwise=True
)

def lla_to_ecef(self) -> pl.Expr:
return self._expr.register_plugin(
lib=lib,
symbol="lla_to_ecef",
is_elementwise=True,
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="lla_to_ecef",
args=self._expr,
is_elementwise=True
)

def lla_to_utm(self) -> pl.Expr:
return self._expr.register_plugin(
lib=lib,
symbol="lla_to_utm",
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="lla_to_utm",
args=self._expr,
is_elementwise=True
)

def lla_to_utm_zone_number(self) -> pl.Expr:
return self._expr.register_plugin(
lib=lib,
symbol="lla_to_utm_zone_number",
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="lla_to_utm_zone_number",
args=self._expr,
is_elementwise=True
)

def rotate_map_coords(self, rotation: pl.Expr, scale: pl.Expr) -> pl.Expr:
return self._expr.register_plugin(
lib=lib,
symbol="rotate_map_coords",
is_elementwise=True,
args=[rotation, scale],
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="rotate_map_coords",
args=[self._expr, rotation, scale],
is_elementwise=True
)


def interpolate_linear(self, other: pl.Expr, coef=0.5):
if coef < 0 or coef > 1:
raise ValueError("`coef` parameter must be between 0 and 1!")

return self._expr.register_plugin(
lib=lib,
symbol="interpolate_linear",
is_elementwise=True,
args=[other,],
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="interpolate_linear",
args=[self._expr, other],
kwargs={"coef": coef},
)

def quat_to_euler_angles(self) -> pl.Expr:
return self._expr.register_plugin(
lib=lib,
symbol="quat_to_euler_angles",
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="quat_to_euler_angles",
args=self._expr,
is_elementwise=True
)

Expand All @@ -119,35 +135,38 @@ def __init__(self, expr: pl.Expr):
self._expr = expr

def euclidean_3d(self, other: pl.Expr) -> pl.Expr:
return self._expr.register_plugin(
lib=lib,
symbol="euclidean_3d",
is_elementwise=True,
args=[other],
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="euclidean_3d",
args=[self._expr, other],
is_elementwise=True

)


def euclidean_2d(self, other: pl.Expr) -> pl.Expr:
return self._expr.register_plugin(
lib=lib,
symbol="euclidean_2d",
is_elementwise=True,
args=[other],
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="euclidean_2d",
args=[self._expr, other],
is_elementwise=True

)

def cosine_similarity_2d(self, other: pl.Expr) -> pl.Expr:
return self._expr.register_plugin(
lib=lib,
symbol="cosine_similarity_2d",
is_elementwise=True,
args=[other,]
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="cosine_similarity_2d",
args=[self._expr, other],
is_elementwise=True
)

def cosine_similarity_3d(self, other: pl.Expr) -> pl.Expr:
return self._expr.register_plugin(
lib=lib,
symbol="cosine_similarity_3d",
is_elementwise=True,
args=[other,]
return register_plugin_function(
plugin_path=Path(__file__).parent,
function_name="cosine_similarity_3d",
args=[self._expr, other],
is_elementwise=True
)


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
version = "0.9.1"
version = "0.10.0"
authors = [
{name="Georgy Popov"}
]
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
maturin
patchelf
polars
pytest
mypy
Expand Down

0 comments on commit bd69b14

Please sign in to comment.