Repository: dask/dask
File: dask/dataframe/tests/test_groupby.py (Python)

Code before:
        "sum",
        "prod",
        "first",
        "last",
        "corr",
        "cov",
        "cumprod",
        "cumsum",
        "mean",
        "median",
        "std",
        "var",
    ],
)
def test_groupby_numeric_only_true(func):
    df = pd.DataFrame({"A": [1, 1, 2, 2], "B": [3, 4, 3, 4], "C": ["a", "b", "c", "d"]})
    ddf = dd.from_pandas(df, npartitions=2)
    ddf_result = getattr(ddf.groupby("A"), func)(numeric_only=True)
    pdf_result = getattr(df.groupby("A"), func)(numeric_only=True)
    assert_eq(ddf_result, pdf_result)


@pytest.mark.parametrize("func", ["cov", "corr"])
def test_groupby_numeric_only_false_cov_corr(func):

    if PANDAS_GE_300 and func == "cov":
        # pandas 3.x doesn't support cov of datetime
        # https://github.com/pandas-dev/pandas/pull/60898
        pytest.skip("pandas 3.x doesn't support cov of datetime")

    df = pd.DataFrame(
        {
            "float": [1.0, 2.0, 3.0, 4.0, 5, 6.0, 7.0, 8.0],
            "int": [1, 2, 3, 4, 5, 6, 7, 8],
            "timedelta": pd.to_timedelta([1, 2, 3, 4, 5, 6, 7, 8]),
            "A": 1,
        }
    )
    ddf = dd.from_pandas(df, npartitions=2)
    dd_result = getattr(ddf.groupby("A"), func)(numeric_only=False)
    pd_result = getattr(df.groupby("A"), func)(numeric_only=False)
    assert_eq(dd_result, pd_result)

    dd_result = getattr(ddf.groupby("A"), func)(numeric_only=True)
    pd_result = getattr(df.groupby("A"), func)(numeric_only=True)
    assert_eq(dd_result, pd_result)


@pytest.mark.parametrize("func", ["cumsum", "cumprod"])
def test_groupby_numeric_only_false(func):
    df = pd.DataFrame(

Review comment (suggestion):
Thanks @TomAugspurger! 

Thoughts on changing this to only add the `"timedelta"` column when it's supported? That way we still test `cov` works for the other dtypes 

Code after:
        "sum",
        "prod",
        "first",
        "last",
        "corr",
        "cov",
        "cumprod",
        "cumsum",
        "mean",
        "median",
        "std",
        "var",
    ],
)
def test_groupby_numeric_only_true(func):
    df = pd.DataFrame({"A": [1, 1, 2, 2], "B": [3, 4, 3, 4], "C": ["a", "b", "c", "d"]})
    ddf = dd.from_pandas(df, npartitions=2)
    ddf_result = getattr(ddf.groupby("A"), func)(numeric_only=True)
    pdf_result = getattr(df.groupby("A"), func)(numeric_only=True)
    assert_eq(ddf_result, pdf_result)


@pytest.mark.parametrize("func", ["cov", "corr"])
def test_groupby_numeric_only_false_cov_corr(func):

    df = pd.DataFrame(
        {
            "float": [1.0, 2.0, 3.0, 4.0, 5, 6.0, 7.0, 8.0],
            "int": [1, 2, 3, 4, 5, 6, 7, 8],
            "A": 1,
        }
    )

    if not PANDAS_GE_300:
        # pandas 3.x doesn't support cov of datetime
        # https://github.com/pandas-dev/pandas/pull/60898
        df["timedelta"] = pd.to_timedelta([1, 2, 3, 4, 5, 6, 7, 8])

    ddf = dd.from_pandas(df, npartitions=2)
    dd_result = getattr(ddf.groupby("A"), func)(numeric_only=False)
    pd_result = getattr(df.groupby("A"), func)(numeric_only=False)
    assert_eq(dd_result, pd_result)

    dd_result = getattr(ddf.groupby("A"), func)(numeric_only=True)
    pd_result = getattr(df.groupby("A"), func)(numeric_only=True)
    assert_eq(dd_result, pd_result)


@pytest.mark.parametrize("func", ["cumsum", "cumprod"])
def test_groupby_numeric_only_false(func):
    df = pd.DataFrame(