MCPcopy Create free account
hub / github.com/apache/arrow / test_dataset_project_columns

Function test_dataset_project_columns

python/pyarrow/tests/test_dataset.py:4090–4111  ·  view source on GitHub ↗
(tempdir, dataset_reader)

Source from the content-addressed store, hash-verified

4088
4089
4090def test_dataset_project_columns(tempdir, dataset_reader):
4091 # basic column re-projection with expressions
4092 from pyarrow import feather
4093 table = pa.table({"A": [1, 2, 3], "B": [1., 2., 3.], "C": ["a", "b", "c"]})
4094 feather.write_feather(table, tempdir / "data.feather")
4095
4096 dataset = ds.dataset(tempdir / "data.feather", format="feather")
4097 result = dataset_reader.to_table(dataset, columns={
4098 'A_renamed': ds.field('A'),
4099 'B_as_int': ds.field('B').cast("int32", safe=False),
4100 'C_is_a': ds.field('C') == 'a'
4101 })
4102 expected = pa.table({
4103 "A_renamed": [1, 2, 3],
4104 "B_as_int": pa.array([1, 2, 3], type="int32"),
4105 "C_is_a": [True, False, False],
4106 })
4107 assert result.equals(expected)
4108
4109 # raise proper error when not passing an expression
4110 with pytest.raises(TypeError, match="Expected an Expression"):
4111 dataset_reader.to_table(dataset, columns={"A": "A"})
4112
4113
4114@pytest.mark.pandas

Callers

nothing calls this directly

Calls 5

equalsMethod · 0.80
to_tableMethod · 0.45
fieldMethod · 0.45
castMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected