Repository navigation
Conversation
…rator Expose the C++ file discovery generator as a lazy, flat Python iterator. Fetch entries in batches internally and yield FileInfo objects individually. Start discovery on the first next() call and release resources on exhaustion, error, or close(). Reject concurrent next()/close() calls. LocalFileSystem and native S3FileSystem expose discovery results incrementally, allowing processing to overlap with listing. Other backends retain the C++ single-batch fallback. Document that prefetched work may continue after early termination. Add tests for backend result equivalence, lazy startup, cross-batch iteration, early close, lifetime, Python handler errors, and concurrent operation rejection.
dragongu
requested review from
AlenkaF,
pitrou,
raulcd and
rok
as code owners
November 24, 2026 06:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
FileSystem.get_file_info(selector)materializes the entire listing before returning. The primary use case is processing very large S3 prefixes through PyArrow's nativeS3FileSystem: callers should be able to begin computing on objects from the first listing page while subsequent pages are still being fetched, rather than waiting for the complete listing.Arrow C++ already exposes
FileSystem::GetFileInfoGenerator(). This PR binds that existing functionality to a synchronous Python iterator without changing the C++ filesystem backends or the existingget_file_info()API.What changes are included in this PR?
FileSystem.get_file_info_iterator(selector)and the publicpyarrow.fs.FileInfoIteratortype. The iterator fetches results in batches internally but yields individualFileInfoobjects.next()call. Creating, closing, or deleting an unused iterator does not start listing.close(). Closing is idempotent.next()andclose()calls on the same iterator withValueError, since the underlying C++ generator is not async-reentrant.Incremental discovery depends on the backend. Native
LocalFileSystemandS3FileSystemexpose batches as discovery progresses;SubTreeFileSystemdelegates to its underlying filesystem.GcsFileSystem,AzureFileSystem,HadoopFileSystem, andPyFileSystem(including the fsspec integration) retain the C++ fallback, which materializes the full selection on the firstnext()call before yielding entries from memory. This PR does not add streaming implementations for those backends.Closing an iterator releases its resources but does not guarantee cancellation of work already started by the backend. In particular, this PR does not promise that early termination cancels S3 pagination requests or that backend prefetch memory is strictly bounded.
Are these changes tested?
Yes. The standard CMake
_fstarget was rebuilt and the completepython/pyarrow/tests/test_fs.pysuite was run against the new extension: 191 passed, 406 skipped, 8 xfailed, with exit code 0. The expected failures are existing MockFileSystem serialization limitations.The basic listing and close tests use the existing 13 filesystem configurations, allowing enabled CI environments to exercise the new API on their respective backends. The local environment did not have S3, GCS, Azure, or HDFS enabled, and fsspec configurations were also skipped because the dependency was unavailable. Consequently, S3 pagination behavior was confirmed by source inspection but has not been exercised locally; remote-backend validation remains for CI.
Local lint checks passed: flake8, cython-lint, clang-format 18.1.8, numpydoc validation using the project's configured checks, sphinx-lint, and
git diff --check. Wheel/sdist builds, a full documentation build, and performance benchmarks were not run.Are there any user-facing changes?
Yes. This adds a synchronous, lazy, flat iterator API. Existing
get_file_info()behavior is unchanged, and this PR introduces no breaking changes to existing public APIs.Each item is a
FileInfo, not a list or a batch. Entry order is not guaranteed. When stopping early, callers should explicitly callclose(); exhausting the iterator releases resources automatically. True incremental discovery is currently available through native LocalFileSystem/S3FileSystem and wrappers that preserve their generator implementation, not through the fsspec S3 integration.