Description:
- Work with data in pyarrow. Arrow manages data in arrays, which can be grouped in tables, to represent columns of data in tabular data.
Resources:
- [Fsspec Docs] https://filesystem-spec.readthedocs.io/en/latest/_modules/fsspec/implementations/arrow.html
- [Arrow Docs] https://arrow.apache.org/docs/python/filesystems.html
Environment variables
Section titled “Environment variables”This notebook reads its settings from environment variables. Set them before starting Jupyter:
S3_BUCKET: name of an S3 bucket you can access
Only Example 3 needs it; Examples 1 and 2 use the local filesystem.
Example 1
Section titled “Example 1”Write data to local filesystem
from pyarrow import fsfrom pathlib import Path
tmp_path = "/tmp/ganymede_demo"p = Path(tmp_path).mkdir(exist_ok=True)tmp_fp = f"{tmp_path}/local_fs.dat"
# Instantiate local fslocal = fs.LocalFileSystem()
# Write data to the file as output streamwith local.open_output_stream(tmp_fp) as stream: stream.write(b'data')
# Alternatively, write data to the file as input streamwith local.open_input_stream(tmp_fp) as stream: print(stream.readall())Example 2
Section titled “Example 2”Instantiate ArrowFSWrapper for a local filesystem and list the contents of a folder
from fsspec.implementations.arrow import ArrowFSWrapperfrom pyarrow import fs
fs = fs.LocalFileSystem()arrow_fs = ArrowFSWrapper(fs)
arrow_fs.ls("/tmp/ganymede_demo")Example 3
Section titled “Example 3”Create a filesystem object from a url
import os
from pyarrow import fs
s3, path = fs.FileSystem.from_uri(f"s3://{os.environ['S3_BUCKET']}")print(s3)print(path)ganymede is made by Eugo