def test_typecast_from_float_to_decimal(data, from_dtype, to_dtype): got = data.astype(from_dtype) pa_arr = got.to_arrow().cast( pa.decimal128(to_dtype.precision, to_dtype.scale)) expected = cudf.Series(DecimalColumn.from_arrow(pa_arr)) got = got.astype(to_dtype) assert_eq(got, expected)
def test_typecast_to_decimal(data, from_dtype, to_dtype): actual = data.astype(from_dtype) expected = actual actual = actual.astype(to_dtype) pa_arr = expected.to_arrow().cast( pa.decimal128(to_dtype.precision, to_dtype.scale)) expected = cudf.Series(DecimalColumn.from_arrow(pa_arr)) assert_eq(actual, expected) assert_eq(actual.dtype, expected.dtype)
def test_from_arrow_max_precision(): with pytest.raises(ValueError): DecimalColumn.from_arrow( pa.array([1, 2, 3], type=pa.decimal128(scale=0, precision=19)) )
def test_round_trip_decimal_column(data, typ): pa_arr = pa.array(data, type=typ) col = DecimalColumn.from_arrow(pa_arr) assert pa_arr.equals(col.to_arrow())