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

[BEAM-12030] DataFrame read_* raise FileNotFound for non-existent input #14312

Merged
merged 1 commit into from Mar 29, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions sdks/python/apache_beam/dataframe/io.py
Expand Up @@ -187,12 +187,14 @@ def __init__(
self.splitter = splitter

def expand(self, root):
# TODO(robertwb): Handle streaming (with explicit schema).
paths_pcoll = root | beam.Create([self.path])
first = io.filesystems.FileSystems.match([self.path],
limits=[1
])[0].metadata_list[0].path
with io.filesystems.FileSystems.open(first) as handle:
match = io.filesystems.FileSystems.match([self.path], limits=[1])[0]
if not match.metadata_list:
# TODO(BEAM-12031): This should be allowed for streaming pipelines if
# user provides an explicit schema.
raise FileNotFoundError(f"Found no files that match {self.path!r}")
first_path = match.metadata_list[0].path
with io.filesystems.FileSystems.open(first_path) as handle:
if not self.binary:
handle = TextIOWrapper(handle)
if self.incremental:
Expand Down
5 changes: 5 additions & 0 deletions sdks/python/apache_beam/dataframe/io_test.py
Expand Up @@ -299,6 +299,11 @@ def read_truncated_csv(start, stop):
])
assert_frame_equal(expected, split_at_header)

def test_file_not_found(self):
with self.assertRaisesRegex(FileNotFoundError, r'/tmp/fake_dir/\*\*'):
with beam.Pipeline() as p:
p | io.read_csv('/tmp/fake_dir/**')


if __name__ == '__main__':
unittest.main()