Example #1
0
def test_to_numeric_error(data, errors):
    if errors == "raise":
        with pytest.raises(
                ValueError,
                match="Unable to convert some strings to numerics."):
            cudf.to_numeric(data, errors=errors)
    else:
        expect = pd.to_numeric(data, errors=errors)
        got = cudf.to_numeric(data, errors=errors)

        assert_eq(expect, got)
Example #2
0
def test_to_numeric_downcast_string_float(data, downcast):
    ps = pd.Series(data)
    gs = cudf.from_pandas(ps)

    expected = pd.to_numeric(ps, downcast=downcast)

    if downcast in {"signed", "integer", "unsigned"}:
        with pytest.warns(
                UserWarning,
                match="Downcasting from float to int "
                "will be limited by float32 precision.",
        ):
            got = cudf.to_numeric(gs, downcast=downcast)
    else:
        got = cudf.to_numeric(gs, downcast=downcast)

    assert_eq(expected, got)
Example #3
0
def test_to_numeric_downcast_string_int(data, downcast):
    ps = pd.Series(data)
    gs = cudf.from_pandas(ps)

    expected = pd.to_numeric(ps, downcast=downcast)
    got = cudf.to_numeric(gs, downcast=downcast)

    assert_eq(expected, got)
Example #4
0
def test_to_numeric_downcast_large_float_pd_bug(data, downcast):
    ps = pd.Series(data)
    gs = cudf.from_pandas(ps)

    expected = pd.to_numeric(ps, downcast=downcast)
    got = cudf.to_numeric(gs, downcast=downcast)

    # Pandas bug: https://github.com/pandas-dev/pandas/issues/19729
    with pytest.raises(AssertionError, match="Series are different"):
        assert_eq(expected, got)
Example #5
0
def test_to_numeric_downcast_string_large_float(data, downcast):
    ps = pd.Series(data)
    gs = cudf.from_pandas(ps)

    if downcast == "float":
        expected = pd.to_numeric(ps, downcast=downcast)
        got = cudf.to_numeric(gs, downcast=downcast)

        # Pandas bug: https://github.com/pandas-dev/pandas/issues/19729
        with pytest.raises(AssertionError, match="Series are different"):
            assert_eq(expected, got)
    else:
        expected = pd.Series([np.inf, -np.inf])
        with pytest.warns(
                UserWarning,
                match="Downcasting from float to int "
                "will be limited by float32 precision.",
        ):
            got = cudf.to_numeric(gs, downcast=downcast)

        assert_eq(expected, got)
Example #6
0
def test_to_numeric_basic_1d(data):
    expected = pd.to_numeric(data)
    got = cudf.to_numeric(data)

    assert_eq(expected, got)