-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from abstractqqq/better_api
updated syntax
- Loading branch information
Showing
10 changed files
with
502 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
from .iban import IbanExt # noqa: E402 | ||
from .isin import IsinExt # noqa: E402 | ||
from .cusip import CusipExt # noqa: E402 | ||
from .url import UrlExt # noqa: E402 | ||
from .iban import * # noqa: E402, F403 | ||
from .isin import * # noqa: E402, F403 | ||
from .cusip import * # noqa: E402, F403 | ||
from .url import * # noqa: E402, F403 | ||
|
||
__version__ = "0.1.0" | ||
__all__ = ["IbanExt", "IsinExt", "CusipExt", "UrlExt"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import polars as pl | ||
from typing import Any, Optional, List, Dict | ||
from .type_alias import StrOrExpr | ||
|
||
|
||
def str_to_expr(x: StrOrExpr) -> pl.Expr: | ||
if isinstance(x, str): | ||
return pl.col(x) | ||
elif isinstance(x, pl.Expr): | ||
return x | ||
else: | ||
raise ValueError("Can only parse str (column name) or Polars expressions.") | ||
|
||
|
||
def pl_plugin( | ||
*, | ||
lib: str, | ||
symbol: str, | ||
args: List[StrOrExpr], | ||
kwargs: Optional[Dict[str, Any]] = None, | ||
is_elementwise: bool = False, | ||
returns_scalar: bool = False, | ||
changes_length: bool = False, | ||
cast_to_supertype: bool = False, | ||
) -> pl.Expr: | ||
# pl.__version__ should always be a valid version number, so split returns always 3 strs | ||
if tuple(int(x) for x in pl.__version__.split(".")) < (0, 20, 16): | ||
# This will eventually be deprecated? | ||
first = str_to_expr(args[0]) | ||
return first.register_plugin( | ||
lib=lib, | ||
symbol=symbol, | ||
args=[str_to_expr(x) for x in args[1:]], | ||
kwargs=kwargs, | ||
is_elementwise=is_elementwise, | ||
returns_scalar=returns_scalar, | ||
changes_length=changes_length, | ||
cast_to_supertype=cast_to_supertype, | ||
) | ||
|
||
from polars.plugins import register_plugin_function | ||
|
||
return register_plugin_function( | ||
plugin_path=lib, | ||
args=[str_to_expr(x) for x in args], | ||
function_name=symbol, | ||
kwargs=kwargs, | ||
is_elementwise=is_elementwise, | ||
returns_scalar=returns_scalar, | ||
changes_length=changes_length, | ||
cast_to_supertype=cast_to_supertype, | ||
) |
Oops, something went wrong.