Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Mar 17, 2024
1 parent 8330e07 commit ac965c8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 6 additions & 4 deletions narwhals/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ def _flatten_and_extract(self, *args: Any, **kwargs: Any) -> Any:

def _extract_native(self, arg: Any) -> Any:
from narwhals.expression import Expr
from narwhals.pandas_like.namespace import PandasNamespace
from narwhals.series import Series

if self._implementation != "polars":
return arg
if isinstance(arg, BaseFrame):
return arg._dataframe
if isinstance(arg, Series):
return arg._series
if isinstance(arg, Expr):
import polars as pl
if self._implementation == "polars":
import polars as pl

return arg._call(pl)
return arg._call(pl)
plx = PandasNamespace(implementation=self._implementation)
return arg._call(plx)
return arg

def __repr__(self) -> str: # pragma: no cover
Expand Down
5 changes: 2 additions & 3 deletions narwhals/pandas_like/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def parse_into_exprs(


def parse_into_expr(implementation: str, into_expr: IntoPandasExpr) -> PandasExpr:
from narwhals.expression import Expr
from narwhals.pandas_like.expr import PandasExpr
from narwhals.pandas_like.namespace import PandasNamespace
from narwhals.pandas_like.series import PandasSeries
Expand All @@ -105,8 +104,8 @@ def parse_into_expr(implementation: str, into_expr: IntoPandasExpr) -> PandasExp

if isinstance(into_expr, PandasExpr):
return into_expr
if isinstance(into_expr, Expr):
return into_expr._call(plx)
# if isinstance(into_expr, Expr):
# return into_expr._call(plx)
if isinstance(into_expr, PandasSeries):
return plx._create_expr_from_series(into_expr)
if isinstance(into_expr, str):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import warnings
from typing import Any

import modin.pandas as mpd
import numpy as np
import pandas as pd
import polars as pl
Expand All @@ -17,7 +16,7 @@
df_lazy = pl.LazyFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]})
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=UserWarning)
df_mpd = mpd.DataFrame(
df_mpd = pd.DataFrame(
pd.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]})
)

Expand Down

0 comments on commit ac965c8

Please sign in to comment.