Repository navigation
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()andAioS3FileSystem._ls()raiseFileNotFoundErrorfor a key path that is neither an object nor a directory, instead of returning[](#1347).listdir()andtree()of such a path raise too, andS3FileSystem.walk()yields nothing for it with the defaulton_error="omit"(it yielded(path, [], [])).find(),glob(),du(),info(), andexists()are unchanged, and an existing empty bucket still lists as[].- The batch operations of
S3FileSystemraiseValueErrorbefore any transfer for pairs whose result would depend on the order of the transfers (#1344): two pairs ofget,put,copy, orpipewith a dict that have the same destination after normalization,getdestinations that are the same local file or file-like object, and acopydestination that is the source of another pair. For example,copy("b/d/", "b/d/sub/", recursive=True)raises whenb/d/sub/already holds objects.AioS3FileSystemdoes not check these pairs yet (#1398). S3FileSystemandAioS3FileSystemraiseTypeErrorwhenconnection=(or the newclient=) is given together with an argument that builds a client, which they used to ignore (#1378). These arekey/username,secret/password,token,profile/profile_name,anon(alsoanon=False),use_ssl,endpoint_url,connect_timeout,read_timeout,client_kwargs,config_kwargs, and the boto3 session arguments, such asregion_name. A value ofNoneand settings from fsspec's configuration, such asFSSPEC_S3_ENDPOINT_URL, do not count.
Deprecations
connection=ofS3FileSystemandAioS3FileSystememits aDeprecationWarningand will be removed in the next major version (#1378). Usepyathena.filesystem.s3_filesystem(connection)orclient=connection.s3_client, retry_config=connection.retry_config. Instorage_options, replace{"connection": conn}with{"client": conn.s3_client, "retry_config": conn.retry_config}.S3FSCursorstill passesconnection=to a customfilesystem_class, including subclasses ofS3FileSystem, until then (#1386).S3FileSystem.rm(max_workers=)andAioS3FileSystem._rm(max_workers=)are deprecated aliases of the newbatch_size=and emit aDeprecationWarning; giving both raisesTypeError(#1344, #1395).- The
loopargument ofS3AioExecutoris ignored and emits aDeprecationWarning(#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 ofcpu_count() * 5(#1359). The defaults3_max_workersisNone, which takes themax_pool_connectionsof 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_workersabove the client'smax_pool_connectionsopens connections beyond the pool, which urllib3 closes after use with a "Connection pool is full" warning.
S3 filesystem
- The default
max_workersofS3FileSystemandAioS3FileSystemis themax_pool_connectionsof the S3 client (10 unless configured) instead ofcpu_count() * 5, and the files and operations of a filesystem share one request pool ofmax_workersthreads (#1359). With the defaults, a single large read or write runs 10 requests at once. A client that the filesystem builds getsmax_pool_connections = max_workerswhenmax_workersis given andconfig_kwargsdoes not set it; a client given withclient=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
S3FileandAioS3StreamedFileraise a failure, an interrupt, or a cancellation once their running range reads have ended, and an interrupt ofrm()orclear_multipart_uploads()cancels the requests that have not started (#1367). - A cancelled coroutine of
AioS3FileSystem, including one cancelled byasyncio.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 cancelledAioS3StreamedFile.close()waits for its requests before it raises (#1359). - The files of
AioS3FileSystem.open()andS3AioExecutorrun their calls in a thread pool instead of through fsspec's event loop (#1357).S3ThreadPoolExecutorandS3AioThreadPoolare aliases of the newS3ThreadPool, andS3AioExecutoris its subclass, so they are no longer distinct forisinstance(). - In a forked child process, files that the parent opened raise
RuntimeErrorwhen 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
S3Filethat 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()andfind()of a path with a version ID return only that version, namedbucket/key?versionId=<id>, and report a missing version asinfo()does (#1361). They used to list the keys underkey/.- A common prefix with an empty segment, such as
dir//, is listed as the directorybucket/dir/instead ofbucket/dir(#1361). S3FileSystem.glob()and the expansion ofget(),copy(),cat(), andrm()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
FileNotFoundErrorinstead ofPermissionErrorfrominfo(),cat_file(),open(), andS3Core.head_object()/get_object(), andexists()returnsFalsefor it (#1345). - Request parameters that botocore rejects raise
ValueErrorfrom every filesystem call, with botocore'sParamValidationErroras the__cause__(#1389). Before, onlymkdir()converted it, with its own message. rm_file()rejectsBucket,Key, andVersionId, andtouch()rejectsBody, withTypeError(#1377).- A read-mode
open()sends the caller'sIfMatchas 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()ignorescache_typeandcache_options(#1399).AioS3FileSystem._get()pairs its paths asS3FileSystem.get()does, and each of its downloads getsmax(1, max_workers // n)range reads fornfiles.
Connections and to_sql()
- With
role_arnorserial_number, the profile, key, andbotocore_sessionarguments sign only the STS requests; the connection's Athena, Glue, and S3 clients use a new botocore session (#1366). The upload workers ofto_sql()get the connection's current credentials, which are not refreshed during the uploads. to_sql()runs its SQL on an internalCursorwhatever 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 anAioConnection, it runs synchronously instead of failing.
Improvements
S3FileSystemandAioS3FileSystemtake a boto3 S3 client withclient=and a retry policy withretry_config=, andpyathena.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 withclient=orconnection=, or a file it opened for reading, raisesTypeErrorwith guidance.cat,cat_ranges,get,put,pipewith a dict,copy, andmvofS3FileSystemtransfer objects concurrently, at mostbatch_sizeat once (a new argument;max_workersby default) (#1344).rm(batch_size=)is the number of DeleteObjects requests sent at once.get()andget_file()download each object in parallel ranges of the block size, up tomax_workersat once, and hold at most one wave of ranges in memory (#1399).- The S3 filesystem retries
SlowDown,ServiceUnavailable,InternalError, andRequestTimeoutwhen theexceptionsof its retry policy are the default codes (#1400), and so doesto_sql()with the connection's default policy, for its uploads and, withif_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
S3FileSystemandAioS3FileSystemaccepts anos.PathLikepath, such aspathlib.PurePosixPath("bucket/key")(#1394). Many methods raisedTypeErrororAttributeErrorfor one, andget()andput()wrote to the wrong place. The path parameters are annotatedstr | os.PathLike[str], so a subclass that overrides one withpath: strgets a mypy error. RequestPayer,ExpectedBucketOwner, andSSECustomer*set ins3_additional_kwargsare 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 anSSECustomerKeythere, every object that the filesystem reads or copies must be encrypted with that key.S3FileSystemhasclose()and supportswith, which release the idle threads of its request pool; the filesystem stays usable (#1359).- New public APIs:
S3Executor.map()andmap_async()withS3MapResult(#1367),S3ClientError.code_of()(#1367, #1389),S3Core.copy_source_params()(#1362), andS3Core.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_arnorserial_numberkeep working pastduration_seconds: they refresh the STS credentials before they expire, and withserial_numberthey prompt for an MFA code again (#1366). to_sql(if_exists="replace")raisesOperationalError, 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, andto_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 doessetxattr()(#1362).rm_file()sends the parameters that DeleteObject accepts, such asRequestPayer, andmkdir()those of CreateBucket (#1377). - The metadata methods of
S3File(metadata(),getxattr(),url(), andsetxattr()) send the file's request parameters; an append pins the existing object that it reads or copies;"ab","xb", andmode="create"treat a key that is only a prefix of other keys as no object; andcommit()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()withmaxdepth,walk(), andtree()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 raisingAttributeErrorafter truncating the destination (#1399).- A stream
Bodygiven toS3Core.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[], andS3Core.call()resolves the operation of afunctools.partial(#1345).AioS3FileSystem: a recursive_put()no longer sends HeadBucket or CreateBucket for each local directory;_expand_path()passesrefresh=andprefix=to the listing;_rm(batch_size=)is used instead of ignored, andmax_workersis no longer sent to DeleteObjects;_cp_file()no longer sendsrecursive,maxdepth, andon_errorto CopyObject (#1395).PolarsCursorreads a whole CSV result with PyAthena's S3 filesystem instead of the filesystem registered fors3in fsspec, unlessstorage_optionsis given (#1365).
What's Changed
- Add s3fs as an API of the filesystem benchmark suite by @laughingman7743 in #1319
- Add the objects suite of batch operations over many S3 objects by @laughingman7743 in #1320
- Record the filesystem comparison with s3fs (GH-1318) by @laughingman7743 in #1321
- Run fsspec's conformance tests against the S3 filesystems by @laughingman7743 in #1331
- Translate delete-marker versions to FileNotFoundError and fix two S3Core edge cases (GH-1338) by @laughingman7743 in #1345
- Document that copies of a delete-marker source version raise OSError(EINVAL) (GH-1346) by @laughingman7743 in #1348
- Bump setuptools from 83.0.0 to 84.1.0 by @dependabot[bot] in #1350
- Audit the asyncio filesystem tests (GH-1328) by @laughingman7743 in #1349
- Raise FileNotFoundError from ls() of a missing key path (GH-1330) by @laughingman7743 in #1347
- Make files usable after fork with either filesystem (GH-1336) by @laughingman7743 in #1353
- Merge the filesystem thread pools into one S3ThreadPool type (GH-1332) by @laughingman7743 in #1357
- Pin instance metadata in fleet tests by @laughingman7743 in #1355
- Keep fleet test leases on a steady clock by @laughingman7743 in #1358
- Share one request pool per filesystem among its files and operations (GH-1332) by @laughingman7743 in #1359
- Replace markdownlint-cli2 with rumdl for Markdown linting (GH-1352) by @laughingman7743 in #1360
- Fix listings of missing buckets, version paths, and empty key segments (GH-1351, GH-1335) by @laughingman7743 in #1361
- Read Polars CSV results with PyAthena's filesystem and document the synchronous registration by @laughingman7743 in #1365
- Refresh the STS credentials of role_arn and serial_number connections by @laughingman7743 in #1366
- Add a fan-out primitive to the S3 executors (GH-1332) by @laughingman7743 in #1367
- Close configuration gaps left by the rumdl migration (GH-1368) by @laughingman7743 in #1371
- Update the object at the key in a recursive chmod (GH-1335) by @laughingman7743 in #1370
- Send the source's parameters to the lookups of copies and setxattr (GH-1333) by @laughingman7743 in #1362
- Keep the caller's parameters and the open-time pin in S3File by @laughingman7743 in #1369
- Point the MD044 label suppressions to the upstream rumdl issue by @laughingman7743 in #1376
- Remove the Python 3.15 awswrangler and pyarrow markers (GH-1180) by @laughingman7743 in #1379
- Send the authorization parameters of s3_additional_kwargs with every request by @laughingman7743 in #1377
- Update rumdl to 0.3.3 and drop the MyST target workarounds by @laughingman7743 in #1390
- Run the SQL of to_sql() on an internal plain cursor by @laughingman7743 in #1392
- Run the batch operations of S3FileSystem concurrently (GH-1322) by @laughingman7743 in #1344
- Let the caller's parameters take precedence in append mode by @laughingman7743 in #1387
- Raise ValueError for rejected parameters and document S3 error codes (GH-1374) by @laughingman7743 in #1389
- Document the checksum settings of the S3 client by @laughingman7743 in #1393
- Align AioS3FileSystem with S3FileSystem for cancellation and arguments (GH-1337) by @laughingman7743 in #1395
- Inject the filesystem's S3 client with client= and retry_config= (GH-1363) by @laughingman7743 in #1378
- Accept os.PathLike paths in every S3 filesystem method (GH-1380) by @laughingman7743 in #1394
- Bump soupsieve from 2.9 to 4.0 by @dependabot[bot] in #1406
- Close an unclosed S3File outside the pools when it is finalized (GH-1364) by @laughingman7743 in #1396
- Download in parallel ranges in get_file() (GH-1323) by @laughingman7743 in #1399
- Retry the transient S3 errors with the default retry policy (GH-1375) by @laughingman7743 in #1400
- Let the filesystem benchmark suite set the S3 client options (GH-1325) by @laughingman7743 in #1407
- Add benchmark environments for Python 3.15 and 3.15t (GH-1324) by @laughingman7743 in #1409
- List each listed directory by its common prefix in traversals (GH-1401) by @laughingman7743 in #1405
- Give botocore's default retry mode by version in the Retries docs (GH-1411) by @laughingman7743 in #1412
- Retry the S3 errors of to_sql() as the S3 filesystem does (GH-1408) by @laughingman7743 in #1413
- Raise OperationalError when to_sql() cannot delete the replaced objects (GH-1410) by @laughingman7743 in #1415
Full Changelog: v4.2.1...v4.3.0