Skip to content

Commit 39980dc

Browse files
authored
ARROW-16094: [Python] Address docstrings in Filesystems (Utilities) (apache#13582)
Authored-by: Alenka Frim <frim.alenka@gmail.com> Signed-off-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
1 parent 85c0db7 commit 39980dc

3 files changed

Lines changed: 47 additions & 8 deletions

File tree

python/pyarrow/_s3fs.pyx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ def initialize_s3(S3LogLevel log_level=S3LogLevel.Fatal):
4444
----------
4545
log_level : S3LogLevel
4646
level of logging
47+
48+
Examples
49+
--------
50+
>>> fs.initialize_s3(fs.S3LogLevel.Error) # doctest: +SKIP
4751
"""
4852
cdef CS3GlobalOptions options
4953
options.log_level = <CS3LogLevel> log_level
@@ -70,8 +74,8 @@ def resolve_s3_region(bucket):
7074
7175
Examples
7276
--------
73-
>>> resolve_s3_region('ursa-labs-taxi-data')
74-
'us-east-2'
77+
>>> fs.resolve_s3_region('registry.opendata.aws')
78+
'us-east-1'
7579
"""
7680
cdef:
7781
c_string c_bucket

python/pyarrow/conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import pytest
1919
from pyarrow import Codec
20+
from pyarrow import fs
2021

2122
groups = [
2223
'brotli',
@@ -241,3 +242,25 @@ def _docdir(request):
241242

242243
else:
243244
yield
245+
246+
247+
# Define doctest_namespace for fs module docstring import
248+
@pytest.fixture(autouse=True)
249+
def add_fs(doctest_namespace, request, tmp_path):
250+
251+
# Trigger ONLY for the doctests
252+
doctest_m = request.config.option.doctestmodules
253+
doctest_c = getattr(request.config.option, "doctest_cython", False)
254+
255+
if doctest_m or doctest_c:
256+
# fs import
257+
doctest_namespace["fs"] = fs
258+
259+
# Creation of an object and file with data
260+
local = fs.LocalFileSystem()
261+
path = tmp_path / 'fileinfo.dat'
262+
with local.open_output_stream(str(path)) as stream:
263+
stream.write(b'data')
264+
doctest_namespace["local"] = local
265+
doctest_namespace["local_path"] = tmp_path
266+
yield

python/pyarrow/fs.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,28 @@ def copy_files(source, destination,
227227
228228
Examples
229229
--------
230-
Copy an S3 bucket's files to a local directory:
230+
Inspect an S3 bucket's files:
231231
232-
>>> copy_files("s3://your-bucket-name",
233-
... "local-directory") # doctest: +SKIP
232+
>>> s3, path = fs.FileSystem.from_uri(
233+
... "s3://registry.opendata.aws/roda/ndjson/")
234+
>>> selector = fs.FileSelector(path)
235+
>>> s3.get_file_info(selector)
236+
[<FileInfo for 'registry.opendata.aws/roda/ndjson/index.ndjson':...]
234237
235-
Using a FileSystem object:
238+
Copy one file from S3 bucket to a local directory:
236239
237-
>>> copy_files("your-bucket-name", "local-directory",
238-
... source_filesystem=S3FileSystem(...)) # doctest: +SKIP
240+
>>> fs.copy_files("s3://registry.opendata.aws/roda/ndjson/index.ndjson",
241+
... "file:///{}/index_copy.ndjson".format(local_path))
239242
243+
>>> fs.LocalFileSystem().get_file_info(str(local_path)+
244+
... '/index_copy.ndjson')
245+
<FileInfo for '.../index_copy.ndjson': type=FileType.File, size=...>
246+
247+
Copy file using a FileSystem object:
248+
249+
>>> fs.copy_files("registry.opendata.aws/roda/ndjson/index.ndjson",
250+
... "file:///{}/index_copy.ndjson".format(local_path),
251+
... source_filesystem=fs.S3FileSystem())
240252
"""
241253
source_fs, source_path = _resolve_filesystem_and_path(
242254
source, source_filesystem

0 commit comments

Comments
 (0)