Skip to content

Loosen numpy/pandas/pydantic/scikit-learn/narwhals pins so Colab installs don't downgrade - #1287

Merged
jhnwu3 merged 1 commit into
sunlabuiuc:masterfrom
solarsys:fix/loosen-core-pins
Oct 11, 2026
Merged

jhnwu3 merged 1 commit into
sunlabuiuc:masterfrom
solarsys:fix/loosen-core-pins

Conversation

@solarsys

@solarsys solarsys commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Why

Five core dependencies use ~= pins that hold them to one minor version: numpy~=2.2.0, pandas~=2.3.1, pydantic~=2.11.7, scikit-learn~=1.7.0 and narwhals~=2.13.0. Google Colab preinstalls different versions, according to googlecolab/backend-info pip-freeze.txt (updated 2026-10-02, Python 3.13):

Package Colab Pin on master Effect of pip install pyhealth on Colab
numpy 2.1.3 ~=2.2.0 replaced with 2.2.x
pandas 2.2.3 ~=2.3.1 replaced with 2.3.x
pydantic 2.13.5 ~=2.11.7 (<2.12) downgraded to 2.11.x
scikit-learn 1.6.1 ~=1.7.0 replaced with 1.7.x
narwhals 2.26.0 ~=2.13.0 (<2.14) downgraded to 2.13.x

Colab has already imported numpy and pandas by the time a notebook runs pip. After the swap, the first import pyhealth fails with 'numpy.ufunc' object has no attribute '__module__' until the runtime is restarted, and pip prints resolver conflicts for other preinstalled packages. The tutorial series in #1281 works around this with an install cell that restarts the runtime. Once this is released, the plain pip install will work without that restart.

What

Bounded ranges whose lower bounds cover Colab's versions:

  • numpy>=2.1,<3. PyHealth needs NumPy 2 (np.trapezoid in tasks/eegbci.py).
  • pandas>=2.2,<3
  • pydantic>=2.11,<3. It's only used for the dataset config models (field_validator, pydantic v2 API).
  • scikit-learn>=1.6,<2
  • narwhals>=2.13,<3

The upper bounds stay at the next major version because pandas 3, numpy 3 and pydantic 3 compatibility is untested. polars~=1.35.2, mne~=1.10.0, orjson~=3.10 and more-itertools~=10.8.0 already match or don't conflict with Colab, so they're unchanged. This follows the style of #1254.

Tests

I ran the full core suite (python -m unittest discover -t tests -s tests/core, 1463 tests) on macOS with Python 3.13, in two fresh venvs:

Version set numpy pandas pydantic scikit-learn narwhals Result
Newest allowed (pip default) 2.5.3 2.3.3 2.14.0 1.9.1 2.26.0 OK (96 skipped)
Colab's preinstalled versions 2.1.3 2.2.3 2.13.5 1.6.1 2.26.0 OK (96 skipped)

pip resolved pip install -e ".[xgboost]" together with the Colab versions with no conflicts. That confirms no other dependency forces the newer versions. tools/check_pr_rules.py passes.

🤖 Generated with Claude Code

…alls don't downgrade

The ~= pins forced numpy 2.2.x, pandas 2.3.x, pydantic 2.11.x,
scikit-learn 1.7.x and narwhals 2.13.x. Google Colab preinstalls numpy
2.1.3, pandas 2.2.3, pydantic 2.13.5, scikit-learn 1.6.1 and narwhals
2.26.0, so installing PyHealth replaced packages Colab had already
imported and the first import failed until the runtime was restarted.
Use bounded ranges whose lower bounds cover Colab's versions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@solarsys
solarsys requested a review from jhnwu3 October 9, 2026 17:28

@jhnwu3 jhnwu3 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jhnwu3
jhnwu3 merged commit c3ac5e2 into sunlabuiuc:master Oct 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants