fix: declare pyarrow, pin worker interpreter, add CI + cleanup#1
Open
hamed wants to merge 7 commits into
Open
Conversation
bootstrap.sample() calls applyInPandas, which requires Arrow serialization,
but pyarrow was never declared. A clean install produced a package whose
core function raised at runtime:
PySparkImportError: [PACKAGE_NOT_INSTALLED] PyArrow >= 18.0.0 must be
installed; however, it was not found.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Spark spawns Python workers as separate processes, choosing the interpreter from PYSPARK_PYTHON and falling back to `python3` on PATH. That is not the virtualenv interpreter running pytest, so the driver imported pyarrow while every worker died with ModuleNotFoundError, failing all 7 bootstrap tests. Pin PYSPARK_PYTHON and PYSPARK_DRIVER_PYTHON to sys.executable in conftest so the suite runs with no shell setup. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Nothing verified that the declared dependencies were sufficient to install and run the library. Both bugs fixed in the preceding commits were of that shape: they only appeared in an environment where nothing was preinstalled. Install from pyproject alone in a fresh uv venv on every supported interpreter, then run pytest. 3.9 resolves to pyspark 4.0.4 and 3.10+ to 4.2.x, so both resolution paths are covered. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
PySpark warns "does not yet fully support pandas >= 3.0.0" and recommends staying below it. With pandas uncapped the newest interpreter resolved to the least-supported pandas: Python 3.13 pulled pandas 3.0.5 and emitted 14 warnings per test run, while 3.9 resolved to 2.3.3 and emitted none. Capping to <3 drops the suite to zero warnings. Homepage and Issues pointed at github.com/allaei/replicas; the repository is github.com/hamed/replicas. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
test_bootstrap.py and test_metrics.py each defined a session-scoped `spark` fixture calling getOrCreate(). Since getOrCreate returns the same JVM session to every caller, this was not two sessions but one session with two teardowns: whichever module finished first called .stop() while the other might still need it. It passed on collection ordering alone. One fixture in conftest.py, so the session lifetime is unambiguous. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ruff check --fix (import sorting, collections.abc.Sequence over the deprecated typing alias, duplicate notebook imports) and ruff format across the package. README.md and examples/*.ipynb are excluded from the formatter. Ruff rewrites Python inside README code blocks, discarding alignment chosen for readability, and reformatting every notebook cell produced a 420-line diff on a file that still has to be executed. Both remain linted; only reformatting is off, and E402 is ignored for notebooks, where imports sit next to the cell that needs them. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Held back until the existing 11 violations were fixed, so the gate lands green rather than red. Ruff is pinned to the same version as the dev extra: an unpinned linter fails CI on a diff that cannot be reproduced locally. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The test suite had never been run. Doing so surfaced two defects that would
hit any user or contributor installing from a clean environment.
pyarrowwas an undeclared runtime dependencybootstrap.sample()callsapplyInPandas, which requires Arrowserialization.
pyarrowappears nowhere inpyproject.toml, so a cleanpip install replicasproduced a package whose core function raised:Declared as
pyarrow>=4.Spark workers ran the wrong interpreter
With pyarrow present the driver was fine, but every worker died:
Spark spawns workers as separate processes and picks the interpreter from
PYSPARK_PYTHON, falling back topython3onPATH— not the virtualenvrunning pytest. All 7 bootstrap tests failed.
tests/conftest.pynow pinsPYSPARK_PYTHONandPYSPARK_DRIVER_PYTHONtosys.executable.pandaswas uncappedPySpark warns "does not yet fully support pandas >= 3.0.0". Uncapped, the
newest interpreter resolved to the least-supported pandas: 3.13 pulled pandas
3.0.5 and emitted 14 warnings per run, 3.9 resolved to 2.3.3 and emitted none.
Capped to
<3; the suite is now warning-free.One SparkSession fixture, not two
Both test modules defined a session-scoped
sparkfixture callinggetOrCreate(). That is not two sessions but one session with two teardowns —whichever module finished first called
.stop()while the other might stillneed it. It passed on collection ordering alone. Now a single fixture in
conftest.py.CI
The dependency bugs share a shape: they only appear where nothing is
preinstalled.
.github/workflows/test.ymlinstalls frompyproject.tomlalone into a fresh uv venv on Python 3.9-3.13, then runs pytest. 3.9 resolves
to pyspark 4.0.4 and 3.10+ to 4.2.x, so both resolution paths are covered. A
ruff lint/format gate runs alongside, pinned to the dev extra's version.
Housekeeping
ruff check --fixandruff formatacross the package;Homepage/Issuescorrected from
allaei/replicastohamed/replicas.README.mdandexamples/*.ipynbare excluded from the formatter only.Ruff rewrites Python inside README code blocks, discarding alignment chosen
for readability, and reformatting every notebook cell produced a 420-line diff
on a file that still has to be executed. Both remain linted.
Verification
12 passed, zero warnings, on Python 3.13 (pyspark 4.2.0) and on afrom-scratch Python 3.9 env (pyspark 4.0.4). The CI lint and test commands
were each run locally as written. The 5-leg matrix went green on GitHub
runners before the cleanup commits were added.
Still open, not in this PR
examples/precision_recall.ipynbhas 27 code cells and no outputs, so thebootstrap-band plot the README is built around does not render on GitHub.
docs/is empty.pip install replicas; the package is not on PyPI.🤖 Generated with Claude Code