Skip to content

v4.3.0

Latest

Choose a tag to compare

@github-actions github-actions released this 16 Nov 16:53
· 31 commits to master since this release
v4.3.0
fb22bdc

Breaking changes

These concern code that uses S3FileSystem or AioS3FileSystem directly or through fsspec. For the cursors, see the first item of Behavior changes.

  • S3FileSystem.ls() and AioS3FileSystem._ls() raise FileNotFoundError for a key path that is neither an object nor a directory, instead of returning [] (#1347). listdir() and tree() of such a path raise too, and S3FileSystem.walk() yields nothing for it with the default on_error="omit" (it yielded (path, [], [])). find(), glob(), du(), info(), and exists() are unchanged, and an existing empty bucket still lists as [].
  • The batch operations of S3FileSystem raise ValueError before any transfer for pairs whose result would depend on the order of the transfers (#1344): two pairs of get, put, copy, or pipe with a dict that have the same destination after normalization, get destinations that are the same local file or file-like object, and a copy destination that is the source of another pair. For example, copy("b/d/", "b/d/sub/", recursive=True) raises when b/d/sub/ already holds objects. AioS3FileSystem does not check these pairs yet (#1398).
  • S3FileSystem and AioS3FileSystem raise TypeError when connection= (or the new client=) is given together with an argument that builds a client, which they used to ignore (#1378). These are key/username, secret/password, token, profile/profile_name, anon (also anon=False), use_ssl, endpoint_url, connect_timeout, read_timeout, client_kwargs, config_kwargs, and the boto3 session arguments, such as region_name. A value of None and settings from fsspec's configuration, such as FSSPEC_S3_ENDPOINT_URL, do not count.

Deprecations

  • connection= of S3FileSystem and AioS3FileSystem emits a DeprecationWarning and will be removed in the next major version (#1378). Use pyathena.filesystem.s3_filesystem(connection) or client=connection.s3_client, retry_config=connection.retry_config. In storage_options, replace {"connection": conn} with {"client": conn.s3_client, "retry_config": conn.retry_config}. S3FSCursor still passes connection= to a custom filesystem_class, including subclasses of S3FileSystem, until then (#1386).
  • S3FileSystem.rm(max_workers=) and AioS3FileSystem._rm(max_workers=) are deprecated aliases of the new batch_size= and emit a DeprecationWarning; giving both raises TypeError (#1344, #1395).
  • The loop argument of S3AioExecutor is ignored and emits a DeprecationWarning (#1357).

Behavior changes

Result reads of the pandas and Polars cursors

  • PandasCursor, PolarsCursor, and their async and asyncio variants read result files through PyAthena's S3 filesystem with at most 10 parallel requests by default, instead of cpu_count() * 5 (#1359). The default s3_max_workers is None, which takes the max_pool_connections of the connection's S3 client (10 unless configured). To read with more parallel requests, raise the client's connection pool, which raises this default too:

    from botocore.config import Config
    from pyathena import connect
    
    conn = connect(..., s3_config=Config(max_pool_connections=50))

    An s3_max_workers above the client's max_pool_connections opens connections beyond the pool, which urllib3 closes after use with a "Connection pool is full" warning.

S3 filesystem

  • The default max_workers of S3FileSystem and AioS3FileSystem is the max_pool_connections of the S3 client (10 unless configured) instead of cpu_count() * 5, and the files and operations of a filesystem share one request pool of max_workers threads (#1359). With the defaults, a single large read or write runs 10 requests at once. A client that the filesystem builds gets max_pool_connections = max_workers when max_workers is given and config_kwargs does not set it; a client given with client= keeps its own.
  • After a failure or an interrupt, a batch operation starts no further call, stops the retries of the running calls, waits for them, and raises (#1344). Objects that other calls completed before the failure stay written; mv() deletes its sources only after every copy succeeded.
  • Parallel reads of S3File and AioS3StreamedFile raise a failure, an interrupt, or a cancellation once their running range reads have ended, and an interrupt of rm() or clear_multipart_uploads() cancels the requests that have not started (#1367).
  • A cancelled coroutine of AioS3FileSystem, including one cancelled by asyncio.wait_for(), raises once the call that it runs in a thread has ended, instead of at once; a second cancellation raises at once (#1395). A cancelled _put_file(), _pipe_file(), or _get_file() ends its transfer instead of committing in the background, and in a transaction it is discarded instead of committed. The batch coroutines _cat(), _cat_ranges(), _pipe(), _put(), _get(), and _copy() cancel their per-object tasks and wait for them. A cancelled AioS3StreamedFile.close() waits for its requests before it raises (#1359).
  • The files of AioS3FileSystem.open() and S3AioExecutor run their calls in a thread pool instead of through fsspec's event loop (#1357). S3ThreadPoolExecutor and S3AioThreadPool are aliases of the new S3ThreadPool, and S3AioExecutor is its subclass, so they are no longer distinct for isinstance().
  • In a forked child process, files that the parent opened raise RuntimeError when used, and closing them only marks them closed, instead of hanging or committing or aborting the parent's upload (#1353, #1357, #1359). Create a new filesystem in the child.
  • An S3File that is finalized without having been closed, during a cyclic garbage collection or in a thread of the filesystem's pools, is closed and committed in a separate thread after the collection, and the interpreter waits for these closes at exit (#1396). In other threads, its finalizer still closes it before the drop of its last reference returns.
  • ls() and find() of a path with a version ID return only that version, named bucket/key?versionId=<id>, and report a missing version as info() does (#1361). They used to list the keys under key/.
  • A common prefix with an empty segment, such as dir//, is listed as the directory bucket/dir/ instead of bucket/dir (#1361).
  • S3FileSystem.glob() and the expansion of get(), copy(), cat(), and rm() list only the keys that start with the part of the pattern before the first wildcard; the matches are unchanged (#1395).
  • A version that is a delete marker raises FileNotFoundError instead of PermissionError from info(), cat_file(), open(), and S3Core.head_object() / get_object(), and exists() returns False for it (#1345).
  • Request parameters that botocore rejects raise ValueError from every filesystem call, with botocore's ParamValidationError as the __cause__ (#1389). Before, only mkdir() converted it, with its own message.
  • rm_file() rejects Bucket, Key, and VersionId, and touch() rejects Body, with TypeError (#1377).
  • A read-mode open() sends the caller's IfMatch as given instead of replacing it with the ETag that it looked up (#1369). A reopened or unpickled file whose object was replaced fails with 412 (OSError(EINVAL)) instead of reading the new object, and a pickled file contains its request parameters, including an SSE-C key.
  • In append mode, the caller's parameters take precedence over the attributes of the existing object (#1387). The existing encryption is kept only when the caller gives none, and the existing object lock is not kept.
  • get_file() ignores cache_type and cache_options (#1399). AioS3FileSystem._get() pairs its paths as S3FileSystem.get() does, and each of its downloads gets max(1, max_workers // n) range reads for n files.

Connections and to_sql()

  • With role_arn or serial_number, the profile, key, and botocore_session arguments sign only the STS requests; the connection's Athena, Glue, and S3 clients use a new botocore session (#1366). The upload workers of to_sql() get the connection's current credentials, which are not refreshed during the uploads.
  • to_sql() runs its SQL on an internal Cursor whatever the connection's cursor class is, so the options of that class (unload, chunksize, arraysize, converter, and custom arguments) no longer apply to it (#1392). Its table lookup disables query result reuse. With an AioConnection, it runs synchronously instead of failing.

Improvements

  • S3FileSystem and AioS3FileSystem take a boto3 S3 client with client= and a retry policy with retry_config=, and pyathena.filesystem.s3_filesystem(connection) creates a filesystem from a connection's client and policy (#1378). The filesystem borrows the client and does not close it. Pickling a filesystem built with client= or connection=, or a file it opened for reading, raises TypeError with guidance.
  • cat, cat_ranges, get, put, pipe with a dict, copy, and mv of S3FileSystem transfer objects concurrently, at most batch_size at once (a new argument; max_workers by default) (#1344). rm(batch_size=) is the number of DeleteObjects requests sent at once.
  • get() and get_file() download each object in parallel ranges of the block size, up to max_workers at once, and hold at most one wave of ranges in memory (#1399).
  • The S3 filesystem retries SlowDown, ServiceUnavailable, InternalError, and RequestTimeout when the exceptions of its retry policy are the default codes (#1400), and so does to_sql() with the connection's default policy, for its uploads and, with if_exists="replace", the listing and deletion of the existing objects (#1413). A persistent S3 error therefore takes longer to raise. The "Retries" section of the filesystem guide describes how these retries combine with botocore's, whose default retry mode changed in botocore 1.44.0 (#1412).
  • Every public method of S3FileSystem and AioS3FileSystem accepts an os.PathLike path, such as pathlib.PurePosixPath("bucket/key") (#1394). Many methods raised TypeError or AttributeError for one, and get() and put() wrote to the wrong place. The path parameters are annotated str | os.PathLike[str], so a subclass that overrides one with path: str gets a mypy error.
  • RequestPayer, ExpectedBucketOwner, and SSECustomer* set in s3_additional_kwargs are sent with every request whose operation accepts them, including listings, and for the source of a copy (#1377). For example, cat_file() of an SSE-C object works with the key set on the filesystem. With an SSECustomerKey there, every object that the filesystem reads or copies must be encrypted with that key.
  • S3FileSystem has close() and supports with, which release the idle threads of its request pool; the filesystem stays usable (#1359).
  • New public APIs: S3Executor.map() and map_async() with S3MapResult (#1367), S3ClientError.code_of() (#1367, #1389), S3Core.copy_source_params() (#1362), and S3Core.resolve_retry_config() (#1413).
  • New documentation: the checksum settings of the S3 client (#1393) and a comparison of the S3 filesystem with s3fs (#1321).

Bug fixes

  • Connections created with role_arn or serial_number keep working past duration_seconds: they refresh the STS credentials before they expire, and with serial_number they prompt for an MFA code again (#1366).
  • to_sql(if_exists="replace") raises OperationalError, listing the objects that remain, when S3 cannot delete some of the existing objects under the location (#1415). It used to write the new data next to them, so the new table also read the old objects. The table has already been dropped then, and to_sql() deletes objects only when the table exists, so delete the remaining objects before calling it again.
  • Copies and moves send the source's RequestPayer, expected owner, and SSE-C parameters with the lookups of the source, and so does setxattr() (#1362). rm_file() sends the parameters that DeleteObject accepts, such as RequestPayer, and mkdir() those of CreateBucket (#1377).
  • The metadata methods of S3File (metadata(), getxattr(), url(), and setxattr()) send the file's request parameters; an append pins the existing object that it reads or copies; "ab", "xb", and mode="create" treat a key that is only a prefix of other keys as no object; and commit() in read mode does nothing (#1369).
  • chmod(recursive=True) also updates the object at the key when objects lie below it, and updates only the given version of a version path (#1370).
  • A listing of a missing bucket evicts its cached listing (#1361).
  • find() with maxdepth, walk(), and tree() descend into directories whose keys contain ?versionId= or an empty segment, and writes below such directories invalidate their cached listings (#1405).
  • get_file(..., compression=...) decompresses the object instead of raising AttributeError after truncating the destination (#1399).
  • A stream Body given to S3Core.call() is sent from its starting position on each retry, instead of from its end, which could write an empty object (#1400).
  • S3Core.part_ranges(0, block_size) returns [], and S3Core.call() resolves the operation of a functools.partial (#1345).
  • AioS3FileSystem: a recursive _put() no longer sends HeadBucket or CreateBucket for each local directory; _expand_path() passes refresh= and prefix= to the listing; _rm(batch_size=) is used instead of ignored, and max_workers is no longer sent to DeleteObjects; _cp_file() no longer sends recursive, maxdepth, and on_error to CopyObject (#1395).
  • PolarsCursor reads a whole CSV result with PyAthena's S3 filesystem instead of the filesystem registered for s3 in fsspec, unless storage_options is given (#1365).

What's Changed

Full Changelog: v4.2.1...v4.3.0