|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING |
| 4 | + |
1 | 5 | import polars as pl
|
2 |
| -from polars.type_aliases import IntoExpr |
3 | 6 | from polars.plugins import register_plugin_function
|
4 |
| -from pathlib import Path |
5 | 7 |
|
| 8 | +from expression_lib._utils import LIB |
| 9 | + |
| 10 | +if TYPE_CHECKING: |
| 11 | + from expression_lib._typing import IntoExprColumn |
6 | 12 |
|
7 |
| -from expression_lib.utils import parse_into_expr |
8 | 13 |
|
9 |
| -def hamming_distance(expr: IntoExpr, other: IntoExpr) -> pl.Expr: |
10 |
| - expr = parse_into_expr(expr) |
| 14 | +def hamming_distance(expr: IntoExprColumn, other: IntoExprColumn) -> pl.Expr: |
11 | 15 | return register_plugin_function(
|
12 |
| - plugin_path=Path(__file__).parent, |
| 16 | + plugin_path=LIB, |
13 | 17 | args=[expr, other],
|
14 | 18 | function_name="hamming_distance",
|
15 | 19 | is_elementwise=True,
|
16 | 20 | )
|
17 | 21 |
|
18 | 22 |
|
19 |
| -def jaccard_similarity(expr: IntoExpr, other: IntoExpr) -> pl.Expr: |
20 |
| - expr = parse_into_expr(expr) |
| 23 | +def jaccard_similarity(expr: IntoExprColumn, other: IntoExprColumn) -> pl.Expr: |
21 | 24 | return register_plugin_function(
|
22 |
| - plugin_path=Path(__file__).parent, |
| 25 | + plugin_path=LIB, |
23 | 26 | args=[expr, other],
|
24 | 27 | function_name="jaccard_similarity",
|
25 | 28 | is_elementwise=True,
|
26 | 29 | )
|
27 | 30 |
|
28 | 31 |
|
29 | 32 | def haversine(
|
30 |
| - start_lat: IntoExpr, |
31 |
| - start_long: IntoExpr, |
32 |
| - end_lat: IntoExpr, |
33 |
| - end_long: IntoExpr, |
| 33 | + start_lat: IntoExprColumn, |
| 34 | + start_long: IntoExprColumn, |
| 35 | + end_lat: IntoExprColumn, |
| 36 | + end_long: IntoExprColumn, |
34 | 37 | ) -> pl.Expr:
|
35 |
| - start_lat = parse_into_expr(start_lat) |
36 | 38 | return register_plugin_function(
|
37 |
| - plugin_path=Path(__file__).parent, |
| 39 | + plugin_path=LIB, |
38 | 40 | args=[start_lat, start_long, end_lat, end_long],
|
39 | 41 | function_name="haversine",
|
40 | 42 | is_elementwise=True,
|
|
0 commit comments