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

Code before:
        # bool doesn't work in pandas quantile
        df = df.drop(columns="bool")
        npartitions = 1  # https://github.com/dask/dask/issues/9227

    ddf = dd.from_pandas(df, npartitions)

    numeric_only_false_raises = ["sum", "prod", "product", "std", "var", "quantile"]

    # `numeric_only=True` is always supported
    assert_eq(
        getattr(df, func)(numeric_only=True),
        getattr(ddf, func)(numeric_only=True),
    )
    errors = TypeError if pa is None else (TypeError, ArrowNotImplementedError)

    # `numeric_only=False`
    if func in numeric_only_false_raises:
        with pytest.raises(
            errors,
            match="'DatetimeArray' with dtype datetime64.*|"
            "'DatetimeArray' does not implement reduction|could not convert|"
            "'ArrowStringArray' with dtype string"
            "|unsupported operand|no kernel",
        ):
            getattr(ddf, func)(numeric_only=False)

        warning = FutureWarning
    else:
        assert_eq(
            getattr(df, func)(numeric_only=False),
            getattr(ddf, func)(numeric_only=False),
        )
        warning = None

    # `numeric_only` default value
    if PANDAS_GE_200:
        if func in numeric_only_false_raises:
            with pytest.raises(
                errors,
                match="'DatetimeArray' with dtype datetime64.*|"
                "'DatetimeArray' does not implement reduction|could not convert|"
                "'ArrowStringArray' with dtype string"
                "|unsupported operand|no kernel",
            ):
                getattr(ddf, func)()
        else:
            assert_eq(
                getattr(df, func)(),
                getattr(ddf, func)(),
            )
    elif PANDAS_GE_150:

Review comment (suggestion):
I'm guessing the additional error also depends on `DASK_EXPR_ENABLED`, is that right? Is it worth making this conditional as well? (My guess is no. :) )

Code after:
            "dt": [pd.NaT] + [datetime(2011, i, 1) for i in range(1, 8)],
            "str": list("abcdefgh"),
            "timedelta": pd.to_timedelta([1, 2, 3, 4, 5, 6, 7, np.nan]),
            "bool": [True, False] * 4,
        }
    )
    npartitions = 3
    if func == "quantile":
        # bool doesn't work in pandas quantile
        df = df.drop(columns="bool")
        npartitions = 1  # https://github.com/dask/dask/issues/9227

    ddf = dd.from_pandas(df, npartitions)

    numeric_only_false_raises = ["sum", "prod", "product", "std", "var", "quantile"]

    # `numeric_only=True` is always supported
    assert_eq(
        getattr(df, func)(numeric_only=True),
        getattr(ddf, func)(numeric_only=True),
    )
    errors = (
        (ValueError, TypeError)
        if pa is None
        else (ValueError, TypeError, ArrowNotImplementedError)
    )

    # `numeric_only=False`
    if func in numeric_only_false_raises:
        with pytest.raises(
            errors,
            match="'DatetimeArray' with dtype datetime64.*|"
            "'DatetimeArray' does not implement reduction|could not convert|"
            "'ArrowStringArray' with dtype string"
            "|unsupported operand|no kernel|not supported",
        ):
            getattr(ddf, func)(numeric_only=False)

        warning = FutureWarning
    else:
        assert_eq(
            getattr(df, func)(numeric_only=False),
            getattr(ddf, func)(numeric_only=False),
        )
        warning = None

    # `numeric_only` default value
    if PANDAS_GE_200:
        if func in numeric_only_false_raises:
            with pytest.raises(
                errors,