Repository navigation
Make the filesystem package independent of the rest of PyAthena (GH-1388) - #1431
laughingman7743 wants to merge 10 commits into
Conversation
) The filesystem now imports nothing from PyAthena outside pyathena/filesystem/, so that it can be released on its own later. - pyathena.filesystem.s3_retry owns the retry policy (S3RetryConfig, any object with the attributes of RetryConfig is accepted), the retry function, and its own stop scopes. pyathena.util.stop_retries_on() and unstoppable_retries() also enter the filesystem's scopes, so closing a cursor still stops the S3 retries of its reads. - pyathena.filesystem.util keeps the filesystem's own override, user agent, and create_in_thread(). - s3_filesystem() moves to pyathena.fs; pyathena.filesystem.s3_filesystem stays as a deprecated copy that warns until the next major version. - A test fails when a module of the package imports PyAthena outside it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| token = _RETRY_STOP_EVENTS.set((*_RETRY_STOP_EVENTS.get(), event)) | ||
| try: | ||
| yield | ||
| with s3_retry.stop_retries_on(event): |
There was a problem hiding this comment.
Self-review round one (implementation behavior): FINDINGS (2), both repaired.
Scope: git diff 703aaad82bfc0c11b35e35e80b03eba2507835fd..d68b464764c1edbf3653e1ce4dfcb03fc2ceeccb (base = merge-base with master), all 32 changed files.
Covered:
- Stop scopes: every PyAthena path that runs filesystem requests (Arrow reader
stop_retries_on+wait_with_retry_stop,pyathena.aio.util.run_in_thread/create_in_thread/run_in_thread_or_close,pyathena.pandas.util.to_sqlwithS3Core.resolve_retry_config) enters PyAthena's scope, which now also enters the filesystem's; the filesystem's internal scopes (executor batches andrun(), writers, itscreate_in_threadcopy, aborts underunstoppable_retries) only govern filesystem requests. No PyAthena retry runs inside a filesystem-only scope. - Import cycles:
pyathena.filesystem.s3_retry,.s3_core,.util,.s3_async,pyathena.filesystem,pyathena.fs,pyathena.util,pyathena.aio.util,pyathena.pandas.util,pyathena.sqlalchemy.baseeach imported first in a fresh interpreter. - Retry policy:
S3FileSystem(retry_config=pyathena.util.RetryConfig(...)), the defaultS3RetryConfig(), type-preservingwith_exceptions()(copy.copy, so a subclass keeps its type), pickling and fsspec tokenization of the arguments (plain classes, as before). - Tests: the boundary test reports master's
pyathena.utilimport and relative imports out of the package; the link tests fail without the twos3_retryscopes inpyathena.util; the deprecation test checks the warning's attribution.
Findings:
benchmarks/pyathena_bench/filesystem.py:24: the newpyathena.fsimport was out of order under the benchmark's ruff config, whichjust formatdoes not cover;just benchmark testfailed in_benchmark-lint. Repaired in 1324abc;just benchmark test: 363 passed, 1 skipped.- PR body: the import cost was given as "about 25 ms". Measured
import pyathenaafter boto3: 5 ms on master, 32 ms on this branch (importlib.metadata.version()adds about 2.7 ms once fsspec has loadedimportlib.metadata); from a bare interpreter, 20 ms / 117 modules vs 132 ms / 494 modules. The PR body now states these numbers.
Limitations: the pandas, Polars, Arrow, s3fs, and SQLAlchemy suites against Athena were not run locally; the AWS CI covers them once Ready.
| self.exponential_base = exponential_base | ||
|
|
||
|
|
||
| def with_exceptions(config: _PolicyT, exceptions: Iterable[str]) -> _PolicyT: |
There was a problem hiding this comment.
Self-review round two (claims, callers, operations): FINDINGS (3 overstated claims), corrected in the PR body; no code change.
Scope: git diff 703aaad82bfc0c11b35e35e80b03eba2507835fd..1324abc4b052988560a2865bc0d398ad3451392e, the PR body, changed docstrings and docs, the commit messages, and the decision comment on #1388.
Claims checked:
- The filesystem imports nothing from PyAthena:
test_package.py, which flags master's imports. - Retries behave as before: the copied retry loop differs from
pyathena.util.retry_api_call()only by the removedstop_onand Glue unwrapping (diffof both bodies); the copiedcreate_in_thread()differs only in its cross-reference and in using the filesystem's scopes. import pyathenacost: measured (5 → 32 ms after boto3; 20 → 132 ms bare), already in the PR body.- Docs examples (
docs/filesystem.mdBasic usage and Retries) run offline with-W error::DeprecationWarning;pyathena.util.RetryConfig()keeps its type and gains the S3 codes. - Stale references: none left to
pyathena.filesystem.s3_filesystemoutside its deprecation; remainingpyathena.aio.util.create_in_thread/pyathena.util.RetryConfigreferences are on PyAthena's side or describe compatibility. - Tests seen failing with the behavior removed:
test_s3_retry.py(stop check disabled → 6 failures;with_exceptions()mutating its input → 2), plus round one's link and boundary checks.
Corrected in the PR body:
- "accepts any object with the attributes of
RetryConfig":with_exceptions()here copies and assignsexceptions, so the attributes must be settable (a frozen object fails); now stated. - "The value is the same" for the user agent: only with distribution metadata; a bare source tree sends
PyAthena/unknown, and later changes topyathena.user_agent_extrano longer reach the filesystem; now stated. - "Nothing in PyAthena calls them inside such a scope" for
pyathena.util.retries_stopped()/raise_if_stopped(): PyAthena no longer calls them at all; reworded.
Follow-up recorded: #1386 now lists the removal of the deprecated pyathena.filesystem.s3_filesystem() (issuecomment-7064571843).
Deferred: the commit message of d68b464 keeps the shorter "any object with the attributes" wording; rewriting a published commit for it is not worth a force-push.
Limitations: AWS suites outside tests/pyathena/filesystem, test_util, aio/test_util, and test_connection were not run locally.
The filesystem's own scopes, such as those of a cancelled call in its thread pool, stopped only the filesystem's retries. A callable that used pyathena.util.retry_api_call() in S3ThreadPool.run() kept retrying after the cancellation, which it did not before the split. PyAthena's retries and stop checks now observe the filesystem's scopes as well, through s3_retry.retry_stop_events(). Also: the boundary test checks literal import_module()/__import__() names and .pyi files; the aio result-set tests stub their requests with PyAthena's retry function again; the stopped-before-call test no longer sets the event during the request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…H-1388) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| from typing import Any, ClassVar, Generic, TypeVar, cast | ||
|
|
||
| from pyathena.util import override, stop_retries_on | ||
| from pyathena.filesystem.s3_retry import stop_retries_on |
There was a problem hiding this comment.
Independent review (relayed), static: FINDINGS.
Reviewer: Codex CLI 0.169.0, model gpt-6.2-astra (configured reasoning effort max), codex exec --sandbox read-only, session 01a1fea2-ee16-7ce3-9306-ccf39cb7a965. Scope: git diff 703aaad82bfc0c11b35e35e80b03eba2507835fd 1324abc4b052988560a2865bc0d398ad3451392e in a detached snapshot at 1324abc (verified unchanged afterwards), with AGENTS.md and docs/testing.md; no PR text, commit messages, or prior findings were given. No edits, tests, or network were allowed. Covered: package imports (incl. TYPE_CHECKING, Python 3.11), the filesystem's retry policy/user agent/override/create_in_thread(), sync and asyncio reads and writes, executor context propagation, cursor cancellation, Arrow prefetch and close, multipart aborts, unstoppable cleanup, both factory paths, connection=, warning attribution, return types, pickling, fsspec instance caching, retry classification, tests, docs.
Findings (reviewer's severity) and disposition:
- P1
pyathena/filesystem/s3_executor.py:29: a caller-supplied callable usingpyathena.util.retry_api_call()inS3ThreadPool.run()kept retrying (and could commit a write) after cancellation, since the executor's scope only entered the filesystem's variable. Verified; repaired in fb362c7 after the maintainer chose that PyAthena observes both variables:retry_api_call(),retries_stopped(),raise_if_stopped(),wait_with_retry_stop()reads3_retry.retry_stop_events()too. New teststest_filesystem_scope_stops_retriesandtest_wait_with_retry_stop_relays_filesystem_stopfail without it. - P2
s3_core.py:616: withoutretry_config,isinstance(S3Core(client).retry_config, RetryConfig)turns False, and theRetryPolicyannotation breaks a typed assignment toRetryConfig. Verified; accepted and documented in the PR body's behavior changes (the filesystem cannot construct PyAthena's class). - P2
s3_retry.py:228:core.call(..., stop_on=predicate)used to be consumed by PyAthena's retry function and is now sent to botocore. Rejected:S3Core.call()documents**requestas request parameters sent as given; nothing passesstop_on, and the old consumption of a parameter by the retry layer was accidental. - P2
s3_retry.py:110: aRetryConfigsubclass that refuses copying, or a read-onlyexceptions, now fails inwith_exceptions(). Deferred as documented: copying keeps the caller's type (the compatibility asked for in item 2's spirit); the PR body states that the attributes must be settable. - P2
filesystem/util.py:50: a source tree without distribution metadata sendsPyAthena/unknown, and other metadata on the path can advertise another release. Accepted and documented in the PR body; the filesystem cannot readpyathena._versionacross the boundary, and the separate distribution will carry its own version. - P2
s3_retry.py:129: a Glue error wrapped inMetadataExceptionis no longer unwrapped. Rejected: S3 does not returnMetadataException; the unwrapping is Athena-specific by design (Make the filesystem package independent of the rest of PyAthena #1388 item 3). - P2
test_package.py:52: literalimportlib.import_module()calls and.pyifiles escaped the boundary test. Repaired in fb362c7; probe withimport_module('pyathena.util')and__import__('pyathena.connection')is now reported. - P2
tests/pyathena/util.py:188: the sharedretried()stub moved every caller, including the aio result-set tests, to the filesystem's retry function. Repaired in fb362c7:retried()takes the retry function; the aio result-set tests pass PyAthena's (the Arrow reader test keeps the filesystem's, as its fake stands for PyAthena's fsspec filesystem). - P3
test_util.py:430: the copied-context case duplicated executor coverage, and the bridge tests did not distinguish the direction. Repaired in fb362c7: the copied-context case is gone; the reverse direction now has its own tests (item 1). - P3
test_s3_retry.py:173: the stopped-before-call test set the event again during the request. Repaired in fb362c7 with an operation that does not touch the event. - P3
test_s3_retry.py:152: the jitter-spread assertion can fail by chance. Rejected: six uniform draws within 1% of the multiplier have probability about 6e-10; the assertion mirrorstest_util.py. - P3
docs/usage.md:766: the sentence after the edited one says chunked Polars Parquet reads use the library's client, while_iter_parquet_chunks()usess3_filesystem(self.connection). Verified as pre-existing, outside this change; to be filed separately with the maintainer's approval.
Validation after the repairs (fb362c7): just lint, just benchmark test (363 passed, 1 skipped), and the filesystem/util/aio-common/Arrow-reader/connection suites against S3: 2352 passed, 6 skipped. A follow-up independent review of 1324abc..6e195e1 is pending.
There was a problem hiding this comment.
Self-review of the repairs (both perspectives), git range-diff-free narrow pass: 1324abc..6e195e1 (same merge-base 703aaad, appended commits fb362c7 and 6e195e1 only). CLEAN.
Behavior: _stop_events() (pyathena/util.py) keeps the union in scope order and drops the duplicate that a pyathena.util.stop_retries_on() scope puts in both variables, so a single scope still waits on its event instead of polling; retry_api_call() still captures the events once per call; async_retry_api_call() goes through it; pyathena.util.unstoppable_retries() clears both variables, and the filesystem's own unstoppable_retries() inside a stopped PyAthena scope stops only PyAthena retries (documented in the PR body; no code runs one there). The retried() default keeps the filesystem tests' stubs as they were; only the aio result-set tests switch back to PyAthena's function.
Claims: the new docstrings of pyathena.util.stop_retries_on(), retries_stopped(), _stop_events(), and s3_retry.retry_stop_events() match the code and are exercised by test_filesystem_scope_stops_retries / test_wait_with_retry_stop_relays_filesystem_stop (both fail when _stop_events() returns only PyAthena's variable). The PR body and the amendment on #1388 (issuecomment posted 2026-11-22) state the new contract; the API reference lists retries_stopped() and retry_stop_events() (Sphinx build of the working tree: no warnings from changed files; just docs lint clean).
Validation: just lint; just benchmark test 363 passed, 1 skipped; filesystem/util/aio-common/Arrow-reader/connection suites against S3 on fb362c7: 2352 passed, 6 skipped.
There was a problem hiding this comment.
Independent follow-up review #1 (relayed), static: FINDINGS, then repairs.
Reviewer: Codex CLI 0.169.0, gpt-6.2-astra, codex exec --sandbox read-only, session 01a1fecc-dda4-7540-b830-068e967d71af. Scope: git diff 1324abc4..6e195e13 (fb362c7, 6e195e1) in the detached snapshot at 6e195e1 (unchanged afterwards), with its own earlier findings and the amended requirement that PyAthena's retries and stop checks also observe the filesystem's scopes.
The reviewer confirmed the repairs of P1 (executor cancellation now stops a callback's PyAthena retry), the aio result-set stubs, the stopped-before-call test, and the removed duplicate test. New or remaining findings and disposition:
- P2
pyathena/util.py:310: with the union of two variables, the filesystem'sunstoppable_retries()inside a stopped PyAthena scope still reported "stopped" topyathena.util(e.g. an overriddenS3Core.call()checkingpyathena.util.raise_if_stopped()during an abort), unlike before the split. Repaired in f0564ca after the maintainer chose one state: PyAthena keeps no variable of its own and usess3_retry's scopes andretry_stop_events().test_filesystem_unstoppable_block_covers_retriesfails with fb362c7'spyathena/util.py. - P2
pyathena/util.py:310:dict.fromkeys()dedup fails on unhashable events and merges equal ones. Resolved by the same repair (no dedup any more). - P2
tests/pyathena/test_util.py:435: the new bridge tests set the event before entering the scope. Repaired in f0564ca: they set it during the request or the backoff wait (StoppingOperation), or inside the scope for the wait relay. - P2
tests/pyathena/filesystem/test_package.py:65: relativeimport_module("..util", __package__)escaped the check. Repaired in f0564ca (relative literals resolved; probe reported). An aliasedimport_module(from importlib import import_module as load) is not covered: a static check cannot follow arbitrary aliases, and runtime imports are against the repository's rules. - P3
test_package.py:40:__init__.pyiwas not treated as a package initializer. Repaired in f0564ca. - P3
pyathena/util.py:384: per-probe dictionary cost. Resolved by the repair (retries_stopped()delegates tos3_retry). - P3
test_util.py:455: elapsed-time assertion in the new wait-relay test. Repaired: removed; the boundedstop.wait()result already shows the relay. - Restated, dispositions unchanged from the first review: default
core.retry_configtype and annotation (accepted, documented),stop_onthroughS3Core.call()(rejected), copy hooks ofRetryConfigsubclasses (documented), Glue unwrapping (rejected), user agent without metadata (documented), jitter spread (rejected, about 6e-10),docs/usage.md:766(pre-existing).
Self-review of f0564ca (both perspectives): CLEAN. Behavior: one context variable, so every stop scope stops every retry and either unstoppable block clears it, as with master's _RETRY_STOP_EVENTS; retry_api_call() still captures the events once per call and waits on a single event. Claims: the docstrings of pyathena.util.stop_retries_on(), unstoppable_retries(), retries_stopped() and the PR body describe that state; the TODO in pyathena/util.py records the accepted import cost (#1315). Validation: just lint; just benchmark test 363 passed, 1 skipped; filesystem/util/aio-common/Arrow-reader/connection suites against S3: 2355 passed, 6 skipped. An independent follow-up of 6e195e1..f0564ca is pending.
There was a problem hiding this comment.
Independent follow-up review #2 (relayed), static: FINDINGS, then repairs.
Reviewer: Codex CLI 0.169.0, gpt-6.2-astra, codex exec --sandbox read-only, session 01a1fefb-dc44-73d3-99ac-ed08b453bb7c. Scope: git diff 6e195e13..f0564cab in the detached snapshot at f0564ca (unchanged afterwards), against the requirement of one stop state owned by the filesystem with master's semantics. The reviewer confirmed that f0564ca restores master's stop behavior on copied contexts, asyncio tasks, executor callbacks, Arrow prefetch and close, writer checks, and multipart aborts, and that unhashable and equal-comparing events work again.
Findings and disposition:
- P2
tests/pyathena/test_util.py:481: the new relay test set the event before the wait, so a wait that checks only on entry would pass. Repaired in 5f92270: the worker stops the scope after the waiter's first check (_CheckedEvent); the test fails whenwait_with_retry_stop()checks only once. - P2
tests/pyathena/filesystem/test_package.py:73:import_module(".util", package="pyathena")was resolved against the module's package. Repaired in 5f92270 (a literalpackage, positional or keyword, is the anchor; probe reported). Aliasedimport_modulestays out of reach of the static check. - P3
tests/pyathena/test_util.py:419: thebackoffcases could pass after sleeping the whole backoff. Repaired in 5f92270 with the elapsed-time bound of the existingtest_retry_api_call_stopped_by_event. - P2 shared-dict
exceptionsin aRetryConfigsubclass (s3_retry.py:111): same trade-off as before (with_exceptions()copies to keep the caller's type; the attributes must be settable and independent), documented in the PR body. - Restated and unchanged:
stop_onthroughS3Core.call()(rejected),S3Core.retry_configannotation (documented), user agent without metadata (documented),docs/usage.md:766(pre-existing).
Self-review of 5f92270 (both perspectives): CLEAN. Test-only change; each tightened test was seen to fail with the behavior removed (single-check wait) or reports the probe (literal package). tests/pyathena/test_util.py, test_package.py, test_s3_retry.py: 125 passed. A narrow independent follow-up of f0564ca..5f92270 is pending.
There was a problem hiding this comment.
Independent follow-up reviews #3–#5 (relayed), static, narrow (test-only commits): FINDINGS each time, on the test helpers. Reviewer: Codex CLI 0.169.0, gpt-6.2-astra, read-only sandbox, detached snapshots (unchanged afterwards); sessions 01a1ff06-f492-72c0-822b-6b55d492dbbf (5f92270), 01a1ff10-9f9b-79d2-a36c-e941c7dce2f3 (ec8ffbe), 01a1ff16-ef02-7fd1-9d61-bd40d48a5839 (35c42ec).
- Retry processing with API call #3 (on
f0564cab..5f922709): relay-test race between the check and the worker's set (repaired in ec8ffbe: the worker sets the event after the waiter's second check; a single-check wait fails 3/3); keyword-onlyimport_module(name=..., package=...)and a non-stringpackage(repaired in ec8ffbe); scheduling-dependent timing of the backoff cases (declined: same pattern and 10-second margin astest_retry_api_call_stopped_by_event). - Cursor Skips First Row When Listing Partitions #4 (on
5f922709..ec8ffbeb): a timed-out acquire let a broken waiter pass, andpackage=__name__/package=Nonewere resolved wrongly (repaired in 35c42ec; a wait that setsstopon entry fails). - Fix cursor skips first row when listing partitions (fix #4) #5 (on
ec8ffbeb..35c42ec8):import_module("..util", __spec__.parent)escaped the anchor resolution. Repaired differently in d2854c0: the package needs no dynamic import, so the boundary test now reports any call ofimport_module()/__import__()and any import ofimport_module(also catching aliases), instead of resolving anchors. Probe:from importlib import import_module as load,import_module(..., __spec__.parent),__import__(...), andfrom .. import utilare reported;from .s3 import ...is not. The second Fix cursor skips first row when listing partitions (fix #4) #5 finding (a correct waiter usingEvent.wait()instead of pollingis_set()would fail the relay test) is declined: the test, like the existing_CheckedEventtest, checks the polling relay thatwait_with_retry_stop()implements and would change with it.
Self-review of these commits (both perspectives): CLEAN; test-only, each tightened test seen to fail with the named behavior removed. test_util.py, test_package.py, test_s3_retry.py: 125 passed (boundary test 13 passed on d2854c0).
There was a problem hiding this comment.
Closing the independent review loop (maintainer's decision, 2026-11-22). Product code received no further findings after follow-up #2; follow-ups #3–#5 concerned test helpers only. The maintainer chose to mark the PR Ready without another follow-up of d2854c0 (test-only: the boundary test reports any dynamic import), which was checked by probes and the self-review above.
The pre-existing docs/usage.md:766 finding (raised in the first review and both later passes) is repaired in a831618 at the maintainer's request: PolarsCursor reads chunked Parquet results through the connection's shared client when PyArrow is installed and no read options are given (_iter_parquet_chunks() → s3_filesystem(self.connection, ...)); chunked CSV results and whole Parquet results still use Polars' own client (scan_csv(), read_parquet()); ArrowCursor reads through pyarrow's S3FileSystem. just docs lint: clean.
PyAthena's stop scopes now are the filesystem's: pyathena.util's stop_retries_on(), unstoppable_retries(), and retries_stopped() use pyathena.filesystem.s3_retry, and retry_api_call() and wait_with_retry_stop() read s3_retry.retry_stop_events(). Reading the union of two variables still let a stopped PyAthena scope stop a PyAthena retry in the filesystem's unstoppable block, which the single variable before the split did not; the dependency still points only from PyAthena to the filesystem. The bridge tests now set the event after entering the scope, and the boundary test resolves relative import_module() names and treats __init__.pyi as a package initializer. A TODO records that importing pyathena now loads the filesystem, to revisit once it is its own distribution. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The relay test stops the filesystem's scope only after the waiter has checked it, the backoff cases assert that the stop ended the wait early, and the boundary test resolves relative import_module() names against a literal package argument. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A wait that checks the scopes only once could see the stop that the worker set right after the first check. The boundary test also reads import_module() calls whose arguments are all keywords and ignores a package that is not a string. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…H-1388) A relative name resolves against __package__, __name__, or a string literal; another package argument is not followed. The relay test's worker fails instead of setting the event when the waiter stops checking. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolving the anchors of import_module() calls could not follow every form, such as __spec__.parent or an alias of the function. The package needs no dynamic import, so the boundary test now reports any call of import_module() or __import__() and any import of import_module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…H-1388) With PyArrow installed and no read options, chunked Parquet results of PolarsCursor are read through PyAthena's filesystem with the connection's shared S3 client, not through Polars' own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WHAT
The S3 filesystem (
pyathena/filesystem/) no longer imports anything from PyAthena outside its package. PyAthena depends on the filesystem, not the other way round. The change is compatible with 4.x; the decisions are recorded in #1388 (comment).pyathena.filesystem.s3_retryowns the filesystem's retry policy (S3RetryConfig), its retry function, and the retry stop scopes (stop_retries_on(),unstoppable_retries(),retries_stopped(),raise_if_stopped(),retry_stop_events()) with their context variable.pyathena.util.stop_retries_on(),unstoppable_retries(), andretries_stopped()keep their names and documentation and use those scopes, andpyathena.util.retry_api_call()andwait_with_retry_stop()read them throughretry_stop_events(). So there is still one scope state, as before: any stop scope, PyAthena's or one that the filesystem opens (such as for a cancelled call in its thread pool), stops any retry in it, and either unstoppable block lets both run to their end. Closing a cursor or cancelling a task still stops the S3 retries of its reads.RetryConfig, settable as onRetryConfig(RetryPolicy), soS3FileSystem(retry_config=pyathena.util.RetryConfig(...))keeps working, andS3Core.resolve_retry_config()keeps the type of the given policy when it adds the S3 error codes.pyathena.filesystem.utilholds the filesystem's ownoverride, itsuser_agent_extra(stillPyAthena/<version>, read from the installed distribution's metadata), and a copy ofcreate_in_thread()that uses the filesystem's scopes.s3_filesystem()moves topyathena.fs. The pandas, Polars, and s3fs result sets use it from there.pyathena.filesystem.s3_filesystemstays as a copy that only reads the connection'ss3_clientandretry_config, and emits aDeprecationWarning; it will be removed in 5.0.0 together with Remove the filesystem's connection= and pass client= to custom s3fs filesystem classes #1386. Theconnection=arguments are typed with a protocol instead ofpyathena.connection.Connection.docs/filesystem.md,docs/usage.md, and the API reference usepyathena.fs.s3_filesystem()andS3RetryConfig. The "S3 client" section ofdocs/usage.mdalso corrects an existing statement: chunked Parquet results ofPolarsCursorare read through the shared client when PyArrow is installed and no read options are given.tests/pyathena/filesystem/test_package.pyparses every module of the package and fails on an import of PyAthena outside it, including imports underTYPE_CHECKINGand relative imports, and reports any dynamic import (importlib.import_module(),__import__()), which the package does not need.Behavior changes
import pyathenanow loads boto3, fsspec, and the filesystem modules, sincepyathena.utilimportspyathena.filesystem.s3_retry. Measured locally on Python 3.15: with boto3 already loaded (as byconnect()),import pyathenatakes 32 ms instead of 5 ms; from a bare interpreter, 132 ms and 494 modules instead of 20 ms and 117 modules. The no-fsspec property from Replace the filesystem's connection= with client= and retry_config= injection #1363 was a design rationale, not a documented contract, and it was dropped by decision on Make the filesystem package independent of the rest of PyAthena #1388.retry_config,S3FileSystem.core.retry_configis anS3RetryConfiginstead of apyathena.util.RetryConfig, with the same values, andS3Core.retry_configis annotated asRetryPolicy: a type-checked assignment of it to aRetryConfigvariable needs a cast.PyAthenadistribution, instead of readingpyathena.user_agent_extraon each client build. The value is the same for an installed PyAthena (test_s3.pychecks it); a source tree without distribution metadata sendsPyAthena/unknownfrom the filesystem, and a later change topyathena.user_agent_extrano longer reaches the filesystem.WHY
Closes #1388. The filesystem is going to be published as
s3filesystem(decision on #1315), which requires it to stand on its own first.TEST
Tested commit: a831618. The S3 suites ran on f0564ca's code (before only a TODO comment, test-only commits, and docs were added); the unit tests touched afterwards ran on each commit (Python 3.15, local).
just lint: passed.just benchmark test: 363 passed, 1 skipped.just docs lint: passed.sphinx-buildof the working tree: no warnings from the changed files (the existing duplicate-description and docstring-indentation warnings remain).uv run --with "botocore[crt]" --env-file .env pytest -n 4 tests/pyathena/filesystem tests/pyathena/test_util.py tests/pyathena/aio/test_util.py tests/pyathena/aio/test_common.py tests/pyathena/arrow/test_reader.py tests/pyathena/test_connection.py(real S3): 2355 passed, 6 skipped.pyathena.util.stop_retries_on()/unstoppable_retries(), the bridge tests fail; withpyathena.utilreading a separate variable (or the union of both, as in an earlier revision),test_filesystem_scope_stops_retries,test_wait_with_retry_stop_relays_filesystem_stop, ortest_filesystem_unstoppable_block_covers_retriesfail;test_s3_retry.pyfails with the stop check disabled (6) or withwith_exceptions()mutating its input (2); the boundary test reports master'spyathena.utilimport ofs3_core.py, relative imports out of the package, and literal (also relative)import_module()/__import__()names, and acceptsfrom .s3 import …in__init__.pyi.tests.pyathena.util.retried()takes the retry function (default: the filesystem's, asS3Core.call()retries); the aio result-set tests pass PyAthena's. Test stubs of S3 requests (retried(), the direct calls intest_s3_executor.py) now send with the filesystem's retry function, asS3Core.call()does, and the helpers oftest_s3.pyandtest_s3_async.pythat observe the filesystem's stop scopes use itsraise_if_stopped(). With PyAthena's functions they no longer saw the scopes that the filesystem opens itself (5 and 29 failures before these changes).Follow-up:
import pyathenaloading the filesystem is accepted for now and marked with a TODO inpyathena/util.py, to revisit when the filesystem becomes its own distribution (#1315).Not run locally: the pandas, Polars, Arrow, s3fs, and SQLAlchemy suites against Athena; the AWS CI runs them once the PR is Ready.
🤖 Generated with Claude Code