-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
258a016
commit a16ac9b
Showing
10 changed files
with
2,006 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from puffin import containers | ||
from puffin.translate import get_namespace | ||
from puffin.translate import to_original_object | ||
from puffin.translate import to_polars_api | ||
|
||
__version__ = "0.2.6" | ||
|
||
__all__ = ["to_polars_api", "to_original_object", "get_namespace", "containers"] |
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,102 @@ | ||
try: | ||
import polars as pl | ||
except ModuleNotFoundError: | ||
POLARS_AVAILABLE = False | ||
pl = object # type: ignore[assignment] | ||
else: | ||
POLARS_AVAILABLE = True | ||
try: | ||
import pandas as pd | ||
except ModuleNotFoundError: | ||
PANDAS_AVAILABLE = False | ||
pd = object | ||
else: | ||
PANDAS_AVAILABLE = True | ||
try: | ||
import cudf | ||
except ModuleNotFoundError: | ||
CUDF_AVAILABLE = False | ||
cudf = object | ||
else: | ||
CUDF_AVAILABLE = True | ||
try: | ||
import modin.pandas as mpd | ||
except ModuleNotFoundError: | ||
MODIN_AVAILABLE = False | ||
mpd = object | ||
else: | ||
MODIN_AVAILABLE = True | ||
|
||
|
||
from typing import Any | ||
|
||
|
||
def is_lazyframe(obj: Any) -> bool: | ||
if hasattr(obj, "__lazyframe_namespace__"): | ||
return True | ||
if POLARS_AVAILABLE and isinstance( | ||
obj, (pl.DataFrame, pl.LazyFrame, pl.Expr, pl.Series) | ||
): | ||
return isinstance(obj, pl.LazyFrame) | ||
return False | ||
|
||
|
||
def is_dataframe(obj: Any) -> bool: | ||
if hasattr(obj, "__dataframe_namespace__"): | ||
return True | ||
if POLARS_AVAILABLE and isinstance( | ||
obj, (pl.DataFrame, pl.LazyFrame, pl.Expr, pl.Series) | ||
): | ||
return isinstance(obj, pl.DataFrame) | ||
return False | ||
|
||
|
||
def is_expr(obj: Any) -> bool: | ||
if hasattr(obj, "__expr_namespace__"): | ||
return True | ||
if POLARS_AVAILABLE and isinstance( | ||
obj, (pl.DataFrame, pl.LazyFrame, pl.Expr, pl.Series) | ||
): | ||
return isinstance(obj, pl.Expr) | ||
return False | ||
|
||
|
||
def is_series(obj: Any) -> bool: | ||
if hasattr(obj, "__series_namespace__"): | ||
return True | ||
if POLARS_AVAILABLE and isinstance( | ||
obj, (pl.DataFrame, pl.LazyFrame, pl.Expr, pl.Series) | ||
): | ||
return isinstance(obj, pl.Series) | ||
return False | ||
|
||
|
||
def get_implementation(obj: Any) -> str: | ||
if POLARS_AVAILABLE and isinstance( | ||
obj, (pl.DataFrame, pl.LazyFrame, pl.Expr, pl.Series) | ||
): | ||
return "polars" | ||
if PANDAS_AVAILABLE and isinstance(obj, (pd.DataFrame, pd.Series)): | ||
return "pandas" | ||
if CUDF_AVAILABLE and isinstance(obj, (cudf.DataFrame, cudf.Series)): | ||
return "cudf" | ||
if MODIN_AVAILABLE and isinstance(obj, mpd.DataFrame): | ||
return "modin" | ||
msg = f"Unknown implementation: {obj}" | ||
raise TypeError(msg) | ||
|
||
|
||
def is_pandas(obj: Any) -> bool: | ||
return get_implementation(obj) == "pandas" | ||
|
||
|
||
def is_polars(obj: Any) -> bool: | ||
return get_implementation(obj) == "polars" | ||
|
||
|
||
def is_cudf(obj: Any) -> bool: | ||
return get_implementation(obj) == "cudf" | ||
|
||
|
||
def is_modin(obj: Any) -> bool: | ||
return get_implementation(obj) == "modin" |
Oops, something went wrong.