hadrian-reppas commented on code in PR #46961: URL: https://github.com/apache/arrow/pull/46961#discussion_r2194901900
########## python/pyarrow/tests/test_dataset.py: ########## @@ -451,6 +487,67 @@ def test_dataset(dataset, dataset_reader): assert_dataset_fragment_convenience_methods(dataset) +def test_dataset_factory_inspect_schema_promotion(promotable_mockfs): + mockfs, path1, path2 = promotable_mockfs + factory = ds.FileSystemDatasetFactory( + mockfs, [path1, path2], ds.ParquetFileFormat() + ) + + with pytest.raises( + pa.ArrowTypeError, + match='Unable to merge: Field value has incompatible types: int8 vs uint16', + ): + factory.inspect() + + schema = factory.inspect(promote_options='permissive') + expected_schema = pa.schema([ + pa.field('value', pa.int32()), + pa.field('dictionary', pa.dictionary(pa.int16(), pa.string())), + ]) + assert schema.equals(expected_schema) + dataset = factory.finish(schema) + table = dataset.to_table() + expected_table = pa.table({ + 'value': pa.chunked_array([[1, 2], [3, 4]], type=pa.int32()), + 'dictionary': pa.chunked_array([ + pa.DictionaryArray.from_arrays( + pa.array([0, 1], type=pa.int16()), + ['a', 'b'] + ), + pa.DictionaryArray.from_arrays( + pa.array([1, 0], type=pa.int16()), + ['d', 'c'] + ) + ]), + }) + assert table.equals(expected_table) + + # Inspecting only one fragment should not promote the 'value' field + inspected_schema_one_frag = factory.inspect( + promote_options='permissive', fragments=1) + assert inspected_schema_one_frag.field('value').type != pa.int32() Review Comment: According to the `InspectOptions` docstring, > The default value of `1` inspects the schema of the first (in no particular order) fragment only. So we don't know which fragment is going to be inspected and which schema we'll get (even though in practice, I've only ever gotten the first one in the list of paths). So I'm just checking that we aren't getting the unified schema. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org