From 3f47d3862f7c4a095dc5e30f4b9a0993601ca3f9 Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 18 Mar 2024 09:41:26 +0000 Subject: [PATCH 1/6] wip --- narwhals/pandas_like/group_by.py | 7 ++++++- tests/test_common.py | 8 +++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/narwhals/pandas_like/group_by.py b/narwhals/pandas_like/group_by.py index 1fe734197..983c9f5da 100644 --- a/narwhals/pandas_like/group_by.py +++ b/narwhals/pandas_like/group_by.py @@ -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 @@ -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( diff --git a/tests/test_common.py b/tests/test_common.py index 54201e780..4b298d809 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,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]}) ) @@ -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 From a0ecc6419366e104538e24832c13c3503f992d9b Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 18 Mar 2024 09:45:03 +0000 Subject: [PATCH 2/6] only run modin in ci --- .github/workflows/pytest.yml | 2 ++ requirements-dev.txt | 1 - tests/test_common.py | 17 ++++++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index f23bce665..156da02f8 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -28,5 +28,7 @@ jobs: key: ${{ runner.os }}-build-${{ matrix.python-version }} - name: install-reqs run: python -m pip install --upgrade tox virtualenv setuptools pip -r requirements-dev.txt + - name: install-modin + run: python -m pip install --upgrade modin - name: Run pytest run: pytest tests --cov=narwhals --cov=tests --cov-fail-under=50 diff --git a/requirements-dev.txt b/requirements-dev.txt index 452f9c615..dcc57d5f6 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,4 @@ covdefaults -modin[dask] pandas polars pre-commit diff --git a/tests/test_common.py b/tests/test_common.py index 4b298d809..9bcd0e8a8 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -1,5 +1,6 @@ from __future__ import annotations +import os import warnings from typing import Any @@ -14,11 +15,17 @@ df_pandas = pd.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}) df_polars = pl.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}) 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 = pd.DataFrame( - pd.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}) - ) + +if os.environ.get("CI", None): + import modin as mpd + + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=UserWarning) + df_mpd = mpd.DataFrame( + pd.DataFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}) + ) +else: + df_mpd = df_pandas.copy() @pytest.mark.parametrize( From e0917f8f992c5024c2345a2b1ac6ad04a56e4e2b Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 18 Mar 2024 09:59:43 +0000 Subject: [PATCH 3/6] coverage --- narwhals/dataframe.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index ef00cb134..c5b53bc22 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -169,7 +169,9 @@ def __init__( elif (pd := get_pandas()) is not None and isinstance(df, pd.DataFrame): self._dataframe = PandasDataFrame(df, implementation="pandas") self._implementation = "pandas" - elif (mpd := get_modin()) is not None and isinstance(df, mpd.DataFrame): + elif (mpd := get_modin()) is not None and isinstance( + df, mpd.DataFrame + ): # pragma: no cover self._dataframe = PandasDataFrame(df, implementation="modin") self._implementation = "modin" elif (cudf := get_cudf()) is not None and isinstance( @@ -222,7 +224,9 @@ def __init__( elif (pd := get_pandas()) is not None and isinstance(df, pd.DataFrame): self._dataframe = PandasDataFrame(df, implementation="pandas") self._implementation = "pandas" - elif (mpd := get_modin()) is not None and isinstance(df, mpd.DataFrame): + elif (mpd := get_modin()) is not None and isinstance( + df, mpd.DataFrame + ): # pragma: no cover self._dataframe = PandasDataFrame(df, implementation="modin") self._implementation = "modin" elif (cudf := get_cudf()) is not None and isinstance( From b15a65fb7324440eb49ae6e7ca30e2f91d47ee3c Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:00:11 +0000 Subject: [PATCH 4/6] coverage --- narwhals/dataframe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index c5b53bc22..2406cbecf 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -179,7 +179,7 @@ def __init__( ): # pragma: no cover self._dataframe = PandasDataFrame(df, implementation="cudf") self._implementation = "cudf" - elif hasattr(df, "__narwhals_dataframe__"): + elif hasattr(df, "__narwhals_dataframe__"): # pragma: no cover self._dataframe = df.__narwhals_dataframe__() self._implementation = "custom" else: From fc26f3d4ec6558528785d652db7b4105dfc7f5b8 Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:02:41 +0000 Subject: [PATCH 5/6] fixup --- tests/test_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_common.py b/tests/test_common.py index 9bcd0e8a8..0cef13264 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -17,7 +17,7 @@ df_lazy = pl.LazyFrame({"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8, 9]}) if os.environ.get("CI", None): - import modin as mpd + import modin.pandas as mpd with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=UserWarning) From 2a4a01970a521c2e88d46b8475ea693467284675 Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 18 Mar 2024 10:03:41 +0000 Subject: [PATCH 6/6] fixup --- .github/workflows/pytest.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 156da02f8..a20e5e6c1 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -9,7 +9,7 @@ jobs: tox: strategy: matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] os: [windows-latest, ubuntu-latest] runs-on: ${{ matrix.os }} @@ -29,6 +29,6 @@ jobs: - name: install-reqs run: python -m pip install --upgrade tox virtualenv setuptools pip -r requirements-dev.txt - name: install-modin - run: python -m pip install --upgrade modin + run: python -m pip install --upgrade modin[dask] - name: Run pytest run: pytest tests --cov=narwhals --cov=tests --cov-fail-under=50