GH #2744: Fix installation on Python 3.12, 3.13#2769
Conversation
|
Changes required to get tests to pass locally:
Source fixes (backward-compatible with older dep versions):
Test fixes:
Result: 2479 passed, 0 failed, 0 errors (was 28 failed, 5 errors). |
|
Lint warnings were mostly preexisting in master - 751 pre-exsiting warnings in the files touched here, 23k in the repo. I will address the four new warnings caused by these changes. |
|
@rly Yeah same, 3.12 would be nice. Any path forward! |
5cc3952 to
ac63179
Compare
|
The glymur failures on 3.9 are due to glymur using match/case syntax, which was introduced in python 3.10. 3.9 is EOL, so I'm not sure it's worth fixing. |
|
I narrowed the CI matrix, since the AllenSDK does not work on master for 3.9 due to breaking changes in glymur and a lack of version cap on glymur. However, python 3.9 is end of life. I think it would be reasonable to tighten the python compatibility range in an upcoming release to 3.10+, and try to make the package actually install and pass tests on non-EOL versions of python. |
|
All tests are passing: 3.10 ubuntu, and 3.13 for all OSs. Tests were taking a very long time. I slimmed the matrix to only run max, min python versions (3.10, 3.13) on ubuntu and max on the other OSs. I also unpinned many of the test dependencies, since they were many versions behind, removed mock which has been moved into unittest on python 3.10+, and made only ubuntu latest measure coverage. The notebook job was cryptically canceled, which I do not understand. Linting is failing, but not due to changes introduced here. |
ebe718a to
e7246e5
Compare
b5148a9 to
c9cfe5f
Compare
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
c9cfe5f to
b692e4f
Compare
Three pinned dependencies blocked installation on Python 3.12+: - numpy<1.24: no cp312 wheels, distutils removal kills source build - pandas==1.5.3: no cp312 wheels, same distutils issue - scipy<1.11: requires_python="<3.12", resolver rejects outright Dependency changes: - numpy: uncap (numpy 2.x supported after source fixes below) - pandas: relax to >=1.5.3,<3 (2.x supported; 3.0 needs further work) - scipy: uncap (1.14+ supported after interp2d removal) - pynwb: cap <3 to avoid breaking API changes - xarray: unpin <2023.2.0 (pure Python, no breakage found) - pytz: add as explicit dep (was transitive via pandas 1.x) - setuptools: cap <81 (pkg_resources removed in 81+) Source fixes for removed/changed APIs: - scipy.interpolate.interp2d → RectBivariateSpline (removed in 1.14) - ConfigParser.readfp → read_string (removed in Python 3.12) - DataFrame.iteritems() → items() (removed in pandas 2.0) - DataFrame.append() → pd.concat() (removed in pandas 2.0) - pd.to_datetime: add format="ISO8601" for mixed-precision timestamps (pandas 2.x rejects mixed microsecond precision without explicit format) - pd.to_datetime: fix utc="True" (string) → utc=True (bool) bug in behavior_project_cloud_api.py - np.int() → int() (removed in numpy 1.24) - np.NaN/np.NAN → np.nan (removed in numpy 2.0) - np.Inf → np.inf, np.string_ → np.bytes_ (removed in numpy 2.0) - np.product → np.prod, np.in1d → np.isin (removed in numpy 2.0) - np.ediff1d to_begin dtype must match array dtype in numpy 2.0 - np.VisibleDeprecationWarning → try/except import (removed in 2.0) - nwbfile.modules → .processing (pynwb 2.x deprecation) - IndexSeries unit='None' → 'N/A' (pynwb 2.5+ validation) - np.linalg.norm([array, scalar]) → np.vstack (numpy 1.24+ rejects) - aiohttp.ClientSession → lazy property (aiohttp 3.9+ event loop) - groupby().apply() → select column first (pandas 2.2+ behavior) - demixer: add np.isfinite guard after linalg.solve (some LAPACK implementations return inf instead of raising LinAlgError for singular matrices) Notebook fixes: - IPython.core.display → IPython.display (removed in IPython 8.x) in visual_behavior_compare_across_trial_types and visual_behavior_mouse_history notebooks Test fixes: - pytest.warns(None) → warnings.catch_warnings (pytest 8) - mock.called_once_with → assert_called_once() (proper assertion) - Add res.x to MagicMock for scipy.optimize result - rng.choice(inhomogeneous) → rng.integers + index (numpy 1.24+) - Widen curve-fit tolerances for platform variance - Cast dtypes for pynwb 2.x roundtrip and pandas 2.x index changes - subprocess 'python' → sys.executable for venv correctness - Replace flaky test_demix_raises_warning_for_singular_matrix with a result-based assertion in test_demix_point - from mock import → from unittest.mock import (69 test files) - Uncap/modernize test dependency bounds, remove dead weight - Add pandas 2.x datetime regression tests (test_pandas_compat.py) CI: - Update to actions/checkout@v4, actions/setup-python@v5 - Slim matrix to min/max Python (3.10, 3.13) on ubuntu, 3.13 on macOS/windows - Add pip caching, coverage on single matrix element only - Modernize notebook_runner.yml to Python 3.13 - Update nightly.yml to checkout@v4 - Switch notebook runner to ubuntu-latest-8x (32GB RAM) for ecephys notebooks that peak at ~21GB RSS - Change notebook workflow trigger to push on master (expensive job should not run on every pull request) Fixes AllenInstitute#2747, AllenInstitute#2744, AllenInstitute#2746, AllenInstitute#2754 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
b692e4f to
05328c2
Compare
mikejhuang
left a comment
There was a problem hiding this comment.
Approving given that the failing notebook test ran fine locally for Galen.
Overview:
Three pinned dependencies blocked installation on 3.12:
Addresses:
Fixes #2747
Fixes #2744
Fixes #2746
Fixes #2754
etc...
Type of Fix:
functionality to not work as expected)
Solution:
Minimally update the requirements to allow installation on 3.12+:
Also some other requirements problems:
Changes:
Source fixes for APIs removed in the new versions of dependencies:
for singular matrices. Add a finite-check fallback so _demix_point
always falls back to lstsq in these cases.
Test fixes:
None sentinel): test_cache.py, test_smart_download.py
(proper assertion): test_cell_types_cache_unit.py
in numpy 1.24+ array construction): test_fitgaussian2D.py
rejects ragged sequences): conftest.py
nullable boolean for float columns): test_write_nwb.py
different int dtypes): test_behavior_project_cache.py
interpreter): test_runner.py
platform-dependent: scipy.linalg.solve does not consistently raise
LinAlgError for singular matrices across LAPACK implementations.
Move the singular matrix case into test_demix_point to verify
correctness of the result regardless of which internal path is taken.
Notebook fixes:
in visual_behavior_compare_across_trial_types and
visual_behavior_mouse_history notebooks
CI changes:
ecephys notebooks that peak at ~21GB RSS
should not run on every pull request)
Validation:
Tested: installs and imports cleanly on Python 3.10 and 3.12.
Ran local tests that do not require data, no new test failures occur (some were preexisting)
Checklist
Allen Institute Contribution Guidelines
Numpy Standards
appropriate
rc/x.y.z as its merge target
Notes
No active RC branch to merge into, targeting master instead.
This is a near-duplicate of #2768, which I think could be a good merge candidate. However, given the lack of traction with that PR I wanted to make a more focused PR that did the bare minimum to allow installation on 3.12, and to make CI pass. I would be happy with either PR being merged, as long as we can install on 3.12.
Compared to #2768, this PR is similar but also supports numpy 2, which allows this package to run on python 3.13 and get numpy wheels on most platforms. Other test changes and CI changes are minor improvements over #2768, but not substantial.