Skip to content

Commit d028fa8

Browse files
authored
GH-46373: [Python] Exercise fallback case on tests for parquet.read_table in case dataset is not available (#46550)
### Rationale for this change Since we merged: - #39112 The fallback case were dataset is not available is not being tested on parquet.read_table (I did validate myself with a breakpoint). ### What changes are included in this PR? Adds a basic test that checks the exercises that code path and tests the read_table method from `ParquetFile` instead of `ParquetDataset` in case dataset is not available. ### Are these changes tested? Yes via CI. ### Are there any user-facing changes? No * GitHub Issue: #46373 Authored-by: Raúl Cumplido <[email protected]> Signed-off-by: Raúl Cumplido <[email protected]>
1 parent cfff4d5 commit d028fa8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

python/pyarrow/tests/parquet/test_basic.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,31 @@ def test_invalid_source():
169169
pq.ParquetFile(None)
170170

171171

172+
def test_read_table_without_dataset(tempdir):
173+
from unittest import mock
174+
175+
class MockParquetDataset:
176+
def __init__(self, *args, **kwargs):
177+
raise ImportError("MockParquetDataset")
178+
179+
path = tempdir / "test.parquet"
180+
table = pa.table({"a": [1, 2, 3]})
181+
_write_table(table, path)
182+
183+
with mock.patch('pyarrow.parquet.core.ParquetDataset', new=MockParquetDataset):
184+
with pytest.raises(ValueError, match="the 'filters' keyword"):
185+
pq.read_table(path, filters=[('integer', '=', 1)])
186+
with pytest.raises(ValueError, match="the 'partitioning' keyword"):
187+
pq.read_table(path, partitioning=['week', 'color'])
188+
with pytest.raises(ValueError, match="the 'schema' argument"):
189+
pq.read_table(path, schema=table.schema)
190+
# Error message varies depending on OS
191+
with pytest.raises(OSError):
192+
pq.read_table(tempdir)
193+
result = pq.read_table(path)
194+
assert result == table
195+
196+
172197
@pytest.mark.slow
173198
def test_file_with_over_int16_max_row_groups():
174199
# PARQUET-1857: Parquet encryption support introduced a INT16_MAX upper

0 commit comments

Comments
 (0)