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

Code before:
@pytest.mark.parametrize(
    "pandas",
    [
        pd.Series(np.abs(np.random.randn(100))),
        pd.DataFrame(
            {
                "A": np.random.randint(1, 100, size=20),
                "B": np.random.randint(1, 100, size=20),
                "C": np.abs(np.random.randn(20)),
            }
        ),
    ],
)
def test_ufunc_with_reduction(redfunc, ufunc, pandas):
    dask = dd.from_pandas(pandas, 3)

    np_redfunc = getattr(np, redfunc)
    np_ufunc = getattr(np, ufunc)

    if NUMPY_GE_200 and redfunc == "prod" and ufunc in ("floor", "ceil", "trunc"):
        pytest.skip("Numpy started overflowing while we are casting to float")

    if (
        redfunc == "prod"
        and ufunc in ["conj", "square", "negative", "absolute"]
        and isinstance(pandas, pd.DataFrame)
    ):
        # TODO(pandas) follow pandas behaviour?
        # starting with pandas 1.2.0, the ufunc is applied column-wise, and therefore
        # applied on the integer columns separately, overflowing for those columns
        # (instead of being applied on 2D ndarray that was converted to float)
        pytest.xfail("'prod' overflowing with integer columns in pandas 1.2.0")

    with warnings.catch_warnings():
        warnings.simplefilter("ignore", RuntimeWarning)
        warnings.simplefilter("ignore", FutureWarning)
        if dd._dask_expr_enabled():
            import dask_expr as dx

            assert isinstance(np_redfunc(dask), (dd.DataFrame, dd.Series, dx.Scalar))
        else:
            assert isinstance(
                np_redfunc(dask), (dd.DataFrame, dd.Series, dd.core.Scalar)
            )
        assert_eq(np_redfunc(np_ufunc(dask)), np_redfunc(np_ufunc(pandas)))


@pytest.mark.parametrize(
    "pandas",
    [
        pd.Series(np.random.randint(1, 100, size=100)),

Review comment (bug):
I don't feel strongly (definitely feel free to ignore this comment) but `pytest.xfail` might be better here. If this does get fixed upstream in `numpy` or `pandas` (wherever the underlying issue is), then `xfail` will start raising, letting us know we can reinstate this portion of the test. 

Code after:
@pytest.mark.parametrize(
    "pandas",
    [
        pd.Series(np.abs(np.random.randn(100))),
        pd.DataFrame(
            {
                "A": np.random.randint(1, 100, size=20),
                "B": np.random.randint(1, 100, size=20),
                "C": np.abs(np.random.randn(20)),
            }
        ),
    ],
)
def test_ufunc_with_reduction(redfunc, ufunc, pandas):
    dask = dd.from_pandas(pandas, 3)

    np_redfunc = getattr(np, redfunc)
    np_ufunc = getattr(np, ufunc)

    if (
        NUMPY_GE_200
        and redfunc == "prod"
        and ufunc in ("floor", "ceil", "trunc")
        and isinstance(pandas, pd.DataFrame)
    ):
        pytest.skip("Numpy started overflowing while we are casting to float")

    if (
        redfunc == "prod"
        and ufunc in ["conj", "square", "negative", "absolute"]
        and isinstance(pandas, pd.DataFrame)
    ):
        # TODO(pandas) follow pandas behaviour?
        # starting with pandas 1.2.0, the ufunc is applied column-wise, and therefore
        # applied on the integer columns separately, overflowing for those columns
        # (instead of being applied on 2D ndarray that was converted to float)
        pytest.xfail("'prod' overflowing with integer columns in pandas 1.2.0")

    with warnings.catch_warnings():
        warnings.simplefilter("ignore", RuntimeWarning)
        warnings.simplefilter("ignore", FutureWarning)
        if dd._dask_expr_enabled():
            import dask_expr as dx

            assert isinstance(np_redfunc(dask), (dd.DataFrame, dd.Series, dx.Scalar))
        else:
            assert isinstance(
                np_redfunc(dask), (dd.DataFrame, dd.Series, dd.core.Scalar)
            )
        assert_eq(np_redfunc(np_ufunc(dask)), np_redfunc(np_ufunc(pandas)))