Conversation
…st order test_lazy_import removed the modules from sys.modules and imported xarray again, but modules and threads left over from other tests could import them again. Run the check in a fresh interpreter instead, and match module names exactly instead of by prefix. test_default_write_engine emptied sys.meta_path to hide the other netCDF library, which also broke lazy imports of other modules, e.g. of h5netcdf.legacyapi, unless another test had imported them already. Hide only that library with a None entry in sys.modules. Co-authored-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dcherian
approved these changes
Sep 30, 2026
headtr1ck
enabled auto-merge (squash)
September 30, 2026 19:02
felixonmars
added a commit
to felixonmars/archriscv-packages
that referenced
this pull request
Oct 27, 2026
Drop the NaT backport already included in v2026.09.0 and the warning filter now present in Arch packaging. Refresh the PKGBUILD context and retain the datetime input bounds fix. Backport the default-write-engine test fix from upstream PR #11648 to the old test path. Clearing sys.meta_path blocks h5netcdf's lazy import, causing "No module named 'h5netcdf.legacyapi'". Hide only the unwanted backend in sys.modules so the test remains enabled. pydata/xarray#11648 https://github.com/pydata/xarray/blob/v2026.09.0/xarray/coding/times.py#L389-L440 https://github.com/pydata/xarray/blob/v2026.09.0/xarray/tests/test_duck_array_ops.py#L350-L361 https://gitlab.archlinux.org/archlinux/packaging/packages/python-xarray/-/blob/2026.09.0-1/PKGBUILD https://archriscv.felixc.at/.status/logs/python-xarray/python-xarray-2026.09.0-1.log
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.
Description
Two tests depended on which tests ran before them in the same process:
test_lazy_import(backends/test_plugins.py) checks that importing xarray doesn't import optional dependencies like scipy or zarr. It removed those modules fromsys.modulesand imported xarray again. But by then they had long been imported, during collection (e.g. by thehas_*checks inxarray/tests/__init__.py) and by other tests, and modules or threads left over from those tests could import them again after the purge. So the test was flaky, and running it first isn't possible: collection happens before any test, and with xdist there is no global first test.It now runs the check in a fresh interpreter with
subprocess, which is independent of test order and xdist and takes about 0.5 s. It also matches module names exactly instead of by prefix, so e.g.pint_xarrayno longer counts aspint. It still catches regressions: with an eagerimport scipyadded to xarray, it fails withscipy have been imported but should be lazy.test_default_write_engine(backends/test_datatree.py) pretended that the other netCDF library isn't installed by emptyingsys.meta_path. That blocks every import that isn't cached yet, e.g. h5netcdf's lazyfrom .legacyapi import Dataset. So the test failed whenever nothing had importedh5netcdf.legacyapibefore, e.g. always when run on its own (ModuleNotFoundError: No module named 'h5netcdf.legacyapi'), and sometimes with xdist.It now hides only that library with
sys.modules[name] = None. That makesimportlib.util.find_specreturnNoneand imports of it fail, while all other imports keep working. The default engine still correctly falls back to the remaining library.No changes to xarray itself, so no whats-new entry.
AI Disclosure
Tools: Claude Code (Claude Opus 5.5)
🤖 Generated with Claude Code