Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-17228: [Python] dataset.write_data should use Scanner.projected_schema when passed a scanner with projected columns #13756

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/pyarrow/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ def file_visitor(written_file):
# was converted to one of those two. So we can grab the schema
# to build the partitioning object from Dataset.
if isinstance(data, Scanner):
partitioning_schema = data.dataset_schema
partitioning_schema = data.projected_schema
else:
partitioning_schema = data.schema
partitioning = _ensure_write_partitioning(partitioning,
Expand Down
25 changes: 25 additions & 0 deletions python/pyarrow/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4706,3 +4706,28 @@ def test_dataset_filter(tempdir):
"colA": [1, 2],
"col2": ["a", "b"]
})


def test_write_dataset_with_scanner_use_projected_schema(tempdir):
"""
Ensure the projected schema is used to validate partitions for scanner

https://issues.apache.org/jira/browse/ARROW-17228
"""
table = pa.table([pa.array(range(20))], names=["original_column"])
table_dataset = ds.dataset(table)
columns = {
"renamed_column": ds.field("original_column"),
}
scanner = table_dataset.scanner(columns=columns)

ds.write_dataset(
scanner, tempdir, partitioning=["renamed_column"], format="ipc")
with (
pytest.raises(
KeyError, match=r"'Column original_column does not exist in schema"
)
):
ds.write_dataset(
scanner, tempdir, partitioning=["original_column"], format="ipc"
)