From ac965c8c74932cee53baa632bdfde1777820d66e Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Sun, 17 Mar 2024 12:42:00 +0000 Subject: [PATCH] simplify --- narwhals/dataframe.py | 10 ++++++---- narwhals/pandas_like/utils.py | 5 ++--- tests/test_common.py | 3 +-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index 3cce941d1..3f047966b 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -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 diff --git a/narwhals/pandas_like/utils.py b/narwhals/pandas_like/utils.py index 8143b8553..2bc7a8e72 100644 --- a/narwhals/pandas_like/utils.py +++ b/narwhals/pandas_like/utils.py @@ -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 @@ -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): diff --git a/tests/test_common.py b/tests/test_common.py index bef5fdb24..b48fed525 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -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 @@ -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]}) )