Skip to content
Open
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
15 changes: 14 additions & 1 deletion python/pyarrow/parquet/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1887,10 +1887,23 @@ def read_table(source, *, columns=None, use_threads=True,
"the 'schema' argument is not supported when the "
"pyarrow.dataset module is not available"
)
if isinstance(source, list):
raise ValueError(
"the 'source' argument cannot be a list of files "
"when the pyarrow.dataset module is not available"
)

filesystem, path = _resolve_filesystem_and_path(source, filesystem)
if filesystem is not None:
if not filesystem.get_file_info(path).is_file:
raise ValueError(
"the 'source' argument should be "
"an existing .parquet file and not a directory, "
"when the pyarrow.dataset module is not available"
)

source = filesystem.open_input_file(path)
# TODO test that source is not a directory or a list

dataset = ParquetFile(
source, read_dictionary=read_dictionary,
binary_type=binary_type,
Expand Down
15 changes: 13 additions & 2 deletions python/pyarrow/tests/parquet/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.

import os
import sys
from collections import OrderedDict
import io
import warnings
Expand Down Expand Up @@ -185,8 +186,7 @@ def __init__(self, *args, **kwargs):
pq.read_table(path, partitioning=['week', 'color'])
with pytest.raises(ValueError, match="the 'schema' argument"):
pq.read_table(path, schema=table.schema)
# Error message varies depending on OS
with pytest.raises(OSError):
with pytest.raises(ValueError, match="the 'source' argument"):
pq.read_table(tempdir)
result = pq.read_table(path)
assert result == table
Expand Down Expand Up @@ -993,3 +993,14 @@ def test_checksum_write_to_dataset(tempdir):
# checksum verification enabled raises an exception
with pytest.raises(OSError, match="CRC checksum verification"):
_ = pq.read_table(corrupted_file_path, page_checksum_verification=True)


@pytest.mark.parametrize(
"source", ["/tmp/", ["/tmp/file1.parquet", "/tmp/file2.parquet"]])
def test_read_table_raises_value_error_when_ds_is_unavailable(
monkeypatch, source):
Comment on lines +1000 to +1001
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_read_table_raises_value_error_when_ds_is_unavailable(
monkeypatch, source):
def test_read_table_raises_value_error_when_ds_is_unavailable(monkeypatch, source):

# GH-47728
monkeypatch.setitem(sys.modules, "pyarrow.dataset", None)

with pytest.raises(ValueError, match="the 'source' argument"):
pq.read_table(source=source)
Loading