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

Code before:
    with _check_warning(
        func in ["std", "var"] and not PANDAS_GE_200,
        FutureWarning,
        message="numeric_only",
    ):
        result = getattr(ddf, func)()
    assert_eq(expected, result)

    # DataFrameGroupBy
    with record_numeric_only_warnings() as rec_pd:
        expected = getattr(df.groupby("x"), func)()
    with record_numeric_only_warnings() as rec_dd:
        result = getattr(ddf.groupby("x"), func)()
    assert len(rec_pd) == len(rec_dd)
    assert_eq(expected, result)

    # SeriesGroupBy
    with record_numeric_only_warnings() as rec_pd:
        expected = getattr(df.groupby("x").z, func)()
    with record_numeric_only_warnings() as rec_dd:
        result = getattr(ddf.groupby("x").z, func)()
    assert len(rec_pd) == len(rec_dd)
    assert_eq(expected, result)


@pytest.mark.skipif(dd._dask_expr_enabled(), reason="usese legacy frame")
def test_std_columns_int():
    # Make sure std() works when index_by is a df with integer column names
    # Non regression test for issue #3560

    df = pd.DataFrame({0: [5], 1: [5]})
    ddf = dd.from_pandas(df, npartitions=2)
    by = dask.array.from_array([0, 1]).to_dask_dataframe()
    ddf.groupby(by).std()


def test_timeseries():
    df = dask.datasets.timeseries().partitions[:2]
    assert_eq(df.groupby("name").std(), df.groupby("name").std())


@pytest.mark.parametrize("min_count", [0, 1, 2, 3])
def test_with_min_count(min_count):
    dfs = [
        pd.DataFrame(
            {
                "group": ["A", "A", "B"],
                "val1": [np.nan, 2, 3],
                "val2": [np.nan, 5, 6],
                "val3": [5, 4, 9],
            }

Review comment (suggestion):
```suggestion
@pytest.mark.skipif(dd._dask_expr_enabled(), reason="uses legacy frame")
```

Code after:
    # TODO: add deprecation warnings to match pandas
    ctx = contextlib.nullcontext()
    if func != "sum":
        ctx = check_nuisance_columns_warning()
    with ctx, check_numeric_only_deprecation():
        expected = getattr(df, func)()
    with _check_warning(
        func in ["std", "var"] and not PANDAS_GE_200,
        FutureWarning,
        message="numeric_only",
    ):
        result = getattr(ddf, func)()
    assert_eq(expected, result)

    # DataFrameGroupBy
    with record_numeric_only_warnings() as rec_pd:
        expected = getattr(df.groupby("x"), func)()
    with record_numeric_only_warnings() as rec_dd:
        result = getattr(ddf.groupby("x"), func)()
    assert len(rec_pd) == len(rec_dd)
    assert_eq(expected, result)

    # SeriesGroupBy
    with record_numeric_only_warnings() as rec_pd:
        expected = getattr(df.groupby("x").z, func)()
    with record_numeric_only_warnings() as rec_dd:
        result = getattr(ddf.groupby("x").z, func)()
    assert len(rec_pd) == len(rec_dd)
    assert_eq(expected, result)


def test_std_columns_int():
    if DASK_EXPR_ENABLED:
        pytest.skip(reason="uses legacy frame")
    # Make sure std() works when index_by is a df with integer column names
    # Non regression test for issue #3560

    df = pd.DataFrame({0: [5], 1: [5]})
    ddf = dd.from_pandas(df, npartitions=2)
    by = dask.array.from_array([0, 1]).to_dask_dataframe()
    ddf.groupby(by).std()


def test_timeseries():
    df = dask.datasets.timeseries().partitions[:2]
    assert_eq(df.groupby("name").std(), df.groupby("name").std())


@pytest.mark.parametrize("min_count", [0, 1, 2, 3])
def test_with_min_count(min_count):
    dfs = [