MCPcopy Create free account
hub / github.com/apache/arrow / _ensure_single_source

Function _ensure_single_source

python/pyarrow/dataset.py:395–439  ·  view source on GitHub ↗

Treat path as either a recursively traversable directory or a single file. Parameters ---------- path : path-like filesystem : FileSystem or str, optional If an URI is passed, then its path component will act as a prefix for the file paths. Returns ----

(path, filesystem=None)

Source from the content-addressed store, hash-verified

393
394
395def _ensure_single_source(path, filesystem=None):
396 """
397 Treat path as either a recursively traversable directory or a single file.
398
399 Parameters
400 ----------
401 path : path-like
402 filesystem : FileSystem or str, optional
403 If an URI is passed, then its path component will act as a prefix for
404 the file paths.
405
406 Returns
407 -------
408 (FileSystem, list of str or fs.Selector)
409 File system object and either a single item list pointing to a file or
410 an fs.Selector object pointing to a directory.
411
412 Raises
413 ------
414 TypeError
415 If the passed filesystem has wrong type.
416 FileNotFoundError
417 If the referenced file or directory doesn't exist.
418 """
419 from pyarrow.fs import FileType, FileSelector, _resolve_filesystem_and_path
420
421 # at this point we already checked that `path` is a path-like
422 filesystem, path = _resolve_filesystem_and_path(path, filesystem)
423
424 # ensure that the path is normalized before passing to dataset discovery
425 path = filesystem.normalize_path(path)
426
427 # retrieve the file descriptor
428 file_info = filesystem.get_file_info(path)
429
430 # depending on the path type either return with a recursive
431 # directory selector or as a list containing a single file
432 if file_info.type == FileType.Directory:
433 paths_or_selector = FileSelector(path, recursive=True)
434 elif file_info.type == FileType.File:
435 paths_or_selector = [path]
436 else:
437 raise FileNotFoundError(path)
438
439 return filesystem, paths_or_selector
440
441
442def _filesystem_dataset(source, schema=None, filesystem=None,

Callers 1

_filesystem_datasetFunction · 0.85

Calls 4

FileSelectorClass · 0.50
normalize_pathMethod · 0.45
get_file_infoMethod · 0.45

Tested by

no test coverage detected