Skip to content

Commit

Permalink
modin and cudf via pandas
Browse files Browse the repository at this point in the history
  • Loading branch information
FBruzzesi committed Jan 13, 2025
1 parent 529f0a0 commit ded037e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
17 changes: 11 additions & 6 deletions narwhals/_pandas_like/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,19 +767,24 @@ def to_numpy(self, dtype: Any = None, copy: bool | None = None) -> Any:
def to_pandas(self: Self) -> pd.DataFrame:
if self._implementation is Implementation.PANDAS:
return self._native_frame
if self._implementation is Implementation.MODIN:
elif self._implementation is Implementation.CUDF: # pragma: no cover
return self._native_frame.to_pandas()
elif self._implementation is Implementation.MODIN:
return self._native_frame._to_pandas()
return self._native_frame.to_pandas() # pragma: no cover
msg = f"Unknown implementation: {self._implementation}" # pragma: no cover
raise AssertionError(msg)

def to_polars(self: Self) -> pl.DataFrame:
import polars as pl # ignore-banned-import

if self._implementation is Implementation.PANDAS:
return pl.from_pandas(self._native_frame)
if self._implementation is Implementation.MODIN:
return self._native_frame._to_polars() # type: ignore[no-any-return]

raise NotImplementedError
elif self._implementation is Implementation.CUDF: # pragma: no cover
return pl.from_pandas(self._native_frame.to_pandas())
elif self._implementation is Implementation.MODIN:
return pl.from_pandas(self._native_frame._to_pandas())
msg = f"Unknown implementation: {self._implementation}" # pragma: no cover
raise AssertionError(msg)

def write_parquet(self, file: Any) -> Any:
self._native_frame.to_parquet(file)
Expand Down
12 changes: 7 additions & 5 deletions narwhals/_pandas_like/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ def to_numpy(self, dtype: Any = None, copy: bool | None = None) -> Any:
def to_pandas(self: Self) -> pd.Series:
if self._implementation is Implementation.PANDAS:
return self._native_series
elif self._implementation is Implementation.CUDF:
elif self._implementation is Implementation.CUDF: # pragma: no cover
return self._native_series.to_pandas()
elif self._implementation is Implementation.MODIN:
return self._native_series._to_pandas()
Expand All @@ -854,10 +854,12 @@ def to_polars(self: Self) -> pl.DataFrame:

if self._implementation is Implementation.PANDAS:
return pl.from_pandas(self._native_series)
if self._implementation is Implementation.MODIN:
return self._native_series._to_polars() # type: ignore[no-any-return]

raise NotImplementedError
elif self._implementation is Implementation.CUDF: # pragma: no cover
return pl.from_pandas(self._native_series.to_pandas())
elif self._implementation is Implementation.MODIN:
return pl.from_pandas(self._native_series._to_pandas())
msg = f"Unknown implementation: {self._implementation}" # pragma: no cover
raise AssertionError(msg)

# --- descriptive ---
def is_duplicated(self: Self) -> Self:
Expand Down

0 comments on commit ded037e

Please sign in to comment.