Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Mar 18, 2024
1 parent f1e2c28 commit 3f47d38
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 6 additions & 1 deletion narwhals/pandas_like/group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from typing import Callable
from typing import Iterable

from packaging.version import parse

from narwhals.pandas_like.utils import dataframe_from_dict
from narwhals.pandas_like.utils import evaluate_simple_aggregation
from narwhals.pandas_like.utils import horizontal_concat
Expand Down Expand Up @@ -122,7 +124,10 @@ def func(df: Any) -> Any:
out_names.append(result_keys.name)
return pd.Series(out_group, index=out_names)

result_complex = grouped.apply(func, include_groups=False)
if parse(pd.__version__) < parse("2.2.0"):
result_complex = grouped.apply(func)
else:
result_complex = grouped.apply(func, include_groups=False)

if result_simple is not None:
result = pd.concat(
Expand Down
8 changes: 5 additions & 3 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,8 +16,8 @@
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(
mpd.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]})
df_mpd = pd.DataFrame(
pd.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]})
)


Expand Down Expand Up @@ -234,6 +233,9 @@ def test_convert_pandas(df_raw: Any) -> None:


@pytest.mark.parametrize("df_raw", [df_polars, df_pandas, df_mpd])
@pytest.mark.filterwarnings(
r"ignore:np\.find_common_type is deprecated\.:DeprecationWarning"
)
def test_convert_numpy(df_raw: Any) -> None:
result = nw.DataFrame(df_raw).to_numpy()
expected = np.array([[1, 3, 2], [4, 4, 6], [7.0, 8, 9]]).T
Expand Down

0 comments on commit 3f47d38

Please sign in to comment.