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

Function test_union_dataset_from_other_datasets

python/pyarrow/tests/test_dataset.py:3194–3257  ·  view source on GitHub ↗
(tempdir, multisourcefs)

Source from the content-addressed store, hash-verified

3192
3193
3194def test_union_dataset_from_other_datasets(tempdir, multisourcefs):
3195 child1 = ds.dataset('/plain', filesystem=multisourcefs, format='parquet')
3196 child2 = ds.dataset('/schema', filesystem=multisourcefs, format='parquet',
3197 partitioning=['week', 'color'])
3198 child3 = ds.dataset('/hive', filesystem=multisourcefs, format='parquet',
3199 partitioning='hive')
3200
3201 assert child1.schema != child2.schema != child3.schema
3202
3203 assembled = ds.dataset([child1, child2, child3])
3204 assert isinstance(assembled, ds.UnionDataset)
3205
3206 msg = 'cannot pass any additional arguments'
3207 with pytest.raises(ValueError, match=msg):
3208 ds.dataset([child1, child2], filesystem=multisourcefs)
3209
3210 expected_schema = pa.schema([
3211 ('date', pa.date32()),
3212 ('index', pa.int64()),
3213 ('value', pa.float64()),
3214 ('color', pa.string()),
3215 ('week', pa.int32()),
3216 ('year', pa.int32()),
3217 ('month', pa.int32()),
3218 ])
3219 assert assembled.schema.equals(expected_schema)
3220 assert assembled.to_table().schema.equals(expected_schema)
3221
3222 assembled = ds.dataset([child1, child3])
3223 expected_schema = pa.schema([
3224 ('date', pa.date32()),
3225 ('index', pa.int64()),
3226 ('value', pa.float64()),
3227 ('color', pa.string()),
3228 ('year', pa.int32()),
3229 ('month', pa.int32()),
3230 ])
3231 assert assembled.schema.equals(expected_schema)
3232 assert assembled.to_table().schema.equals(expected_schema)
3233
3234 expected_schema = pa.schema([
3235 ('month', pa.int32()),
3236 ('color', pa.string()),
3237 ('date', pa.date32()),
3238 ])
3239 assembled = ds.dataset([child1, child3], schema=expected_schema)
3240 assert assembled.to_table().schema.equals(expected_schema)
3241
3242 expected_schema = pa.schema([
3243 ('month', pa.int32()),
3244 ('color', pa.string()),
3245 ('unknown', pa.string()) # fill with nulls
3246 ])
3247 assembled = ds.dataset([child1, child3], schema=expected_schema)
3248 assert assembled.to_table().schema.equals(expected_schema)
3249
3250 # incompatible schemas, date and index columns have conflicting types
3251 table = pa.table([range(9), [0.] * 4 + [1.] * 5, 'abcdefghj'],

Callers

nothing calls this directly

Calls 5

_create_single_fileFunction · 0.85
equalsMethod · 0.80
schemaMethod · 0.45
stringMethod · 0.45
to_tableMethod · 0.45

Tested by

no test coverage detected