Skip to content

Commit 46ea6cb

Browse files
committed
first attempt at readind daft df
1 parent 5a9c7ef commit 46ea6cb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

narwhals/dependencies.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ def get_dask() -> Any: # pragma: no cover
8585
return sys.modules.get("dask", None)
8686

8787

88+
def get_daft_dataframe() -> Any:
89+
return sys.modules.get("daft.dataframe", None)
90+
91+
8892
def get_dask_dataframe() -> Any:
8993
"""Get dask.dataframe module (if already imported - else return None)."""
9094
return sys.modules.get("dask.dataframe", None)
@@ -244,6 +248,12 @@ def is_cupy_scalar(obj: Any) -> bool:
244248
) # pragma: no cover
245249

246250

251+
def is_daft_dataframe(df: Any) -> bool:
252+
"""TODO docstring!"""
253+
_warn_if_narwhals_df_or_lf(df)
254+
return (daft := get_daft_dataframe()) is not None and isinstance(df, daft.DataFrame)
255+
256+
247257
def is_dask_dataframe(df: Any) -> TypeIs[dd.DataFrame]:
248258
"""Check whether `df` is a Dask DataFrame without importing Dask.
249259

narwhals/translate.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
get_numpy,
1919
get_pandas,
2020
is_cupy_scalar,
21+
is_daft_dataframe,
2122
is_dask_dataframe,
2223
is_duckdb_relation,
2324
is_ibis_table,
@@ -444,6 +445,14 @@ def _from_native_impl( # noqa: C901, PLR0911, PLR0912, PLR0915
444445
.to_narwhals()
445446
)
446447

448+
# stripping to simplest form, TODO full sequence
449+
if is_daft_dataframe(native_object):
450+
return (
451+
version.namespace.from_native_object(native_object)
452+
.compliant.from_native(native_object)
453+
.to_narwhals()
454+
)
455+
447456
# Dask
448457
if is_dask_dataframe(native_object):
449458
if series_only:

0 commit comments

Comments
 (0)