Ejemplo n.º 1
0
def test_build_series_from_nullable_pandas_dtype(pd_dtype, expect_dtype):
    if pd_dtype == pd.StringDtype():
        data = ["a", pd.NA, "c", pd.NA, "e"]
    elif pd_dtype == pd.BooleanDtype():
        data = [True, pd.NA, False, pd.NA, True]
    else:
        data = [1, pd.NA, 3, pd.NA, 5]

    pd_data = pd.Series(data, dtype=pd_dtype)
    gd_data = cudf.Series.from_pandas(pd_data)

    assert gd_data.dtype == expect_dtype

    # check mask
    expect_mask = [True if x is not pd.NA else False for x in pd_data]
    got_mask = mask_to_bools(gd_data._column.base_mask, 0,
                             len(gd_data)).to_array()

    np.testing.assert_array_equal(expect_mask, got_mask)
Ejemplo n.º 2
0
def test_build_df_from_nullable_pandas_dtype(pd_dtype, expect_dtype):
    if pd_dtype == pd.StringDtype():
        data = ["a", pd.NA, "c", pd.NA, "e"]
    elif pd_dtype == pd.BooleanDtype():
        data = [True, pd.NA, False, pd.NA, True]
    else:
        data = [1, pd.NA, 3, pd.NA, 5]

    pd_data = pd.DataFrame.from_dict({"a": data}, dtype=pd_dtype)
    gd_data = cudf.DataFrame.from_pandas(pd_data)

    assert gd_data["a"].dtype == expect_dtype

    # check mask
    expect_mask = [True if x is not pd.NA else False for x in pd_data["a"]]
    got_mask = mask_to_bools(
        gd_data["a"]._column.base_mask, 0, len(gd_data)
    ).values_host

    np.testing.assert_array_equal(expect_mask, got_mask)