Skip to content

Commit

Permalink
Merge pull request #2 from georgypv/feature/comply-with-polars>=1.0.0
Browse files Browse the repository at this point in the history
comply with polars>=1.0.0
  • Loading branch information
georgypv authored Jul 18, 2024
2 parents 6928a81 + 92d7b8d commit 512f6bc
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 85 deletions.
25 changes: 10 additions & 15 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is autogenerated by maturin v1.4.0
# This file is autogenerated by maturin v0.14.17
# To update, run
#
# maturin generate-ci github --platform all
# maturin generate-ci github -m Cargo.toml --platform all -o .github/workflows/CI.yml
#
name: CI

Expand All @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
target: [x86_64, x86, aarch64, armv7, s390x, ppc64le]
target: [x86_64, x86, aarch64, armv7, ppc64le]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand Down Expand Up @@ -91,26 +91,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- run: pip install pyodide-build
- name: Get Emscripten and Python version info
shell: bash
run: |
echo EMSCRIPTEN_VERSION=$(pyodide config get emscripten_version) >> $GITHUB_ENV
echo PYTHON_VERSION=$(pyodide config get python_version | cut -d '.' -f 1-2) >> $GITHUB_ENV
pip uninstall -y pyodide-build
- shell: bash
run: echo EMSCRIPTEN_VERSION=$(pyodide config get emscripten_version) >> $GITHUB_ENV
- uses: mymindstorm/setup-emsdk@v12
with:
version: ${{ env.EMSCRIPTEN_VERSION }}
actions-cache-folder: emsdk-cache
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- run: pip install pyodide-build
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: wasm32-unknown-emscripten
args: --release --out dist -i ${{ env.PYTHON_VERSION }}
args: --release --out dist -i 3.10
sccache: 'true'
rust-toolchain: nightly
- name: Upload wheels
Expand Down Expand Up @@ -152,7 +147,7 @@ jobs:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing *
args: --skip-existing *
- uses: actions/download-artifact@v3
with:
name: wasm-wheels
Expand Down
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 512f6bc

Please sign in to comment.