Skip to content

Commit

Permalink
try harder
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Mar 18, 2024
1 parent 5650996 commit caf41d2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
12 changes: 10 additions & 2 deletions narwhals/pandas_like/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,16 @@ def evaluate_into_expr(
"""
Return list of raw columns.
"""
expr = parse_into_expr(df._implementation, into_expr)
return expr._call(df)
from narwhals.pandas_like.expr import PandasExpr
from narwhals.pandas_like.series import PandasSeries

if isinstance(into_expr, PandasSeries):
return [into_expr]
if isinstance(into_expr, str):
return [df[into_expr]]
if isinstance(into_expr, PandasExpr):
return into_expr._call(df)
raise AssertionError


def evaluate_into_exprs(
Expand Down
1 change: 1 addition & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def test_accepted_dataframes() -> None:


@pytest.mark.parametrize("df_raw", [df_polars, df_pandas, df_mpd])
@pytest.mark.filterwarnings("ignore:.*Passing a BlockManager.*:DeprecationWarning")
def test_convert_pandas(df_raw: Any) -> None:
result = nw.DataFrame(df_raw).to_pandas()
expected = pd.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]})
Expand Down
4 changes: 3 additions & 1 deletion tests/tpch_q1_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
def test_q1(library: str) -> None:
if library == "pandas":
df_raw = pd.read_parquet("tests/data/lineitem.parquet")
df_raw["l_shipdate"] = pd.to_datetime(df_raw["l_shipdate"])
elif library == "polars":
df_raw = pl.scan_parquet("tests/data/lineitem.parquet")
var_1 = datetime(1998, 9, 2)
Expand Down Expand Up @@ -78,7 +79,8 @@ def test_q1(library: str) -> None:
@mock.patch.dict(os.environ, {"NARWHALS_FORCE_GENERIC": "1"})
@pytest.mark.filterwarnings("ignore:.*Passing a BlockManager.*:DeprecationWarning")
def test_q1_w_pandas_agg_generic_path() -> None:
df_raw = pl.read_parquet("tests/data/lineitem.parquet").to_pandas()
df_raw = pd.read_parquet("tests/data/lineitem.parquet")
df_raw["l_shipdate"] = pd.to_datetime(df_raw["l_shipdate"])
var_1 = datetime(1998, 9, 2)
df = nw.LazyFrame(df_raw)
query_result = (
Expand Down

0 comments on commit caf41d2

Please sign in to comment.