Fix module_available() crash when version metadata is missing#11422
Open
C1-BA-B1-F3 wants to merge 2 commits into
Open
Fix module_available() crash when version metadata is missing#11422C1-BA-B1-F3 wants to merge 2 commits into
C1-BA-B1-F3 wants to merge 2 commits into
Conversation
When indexing with a single nested tuple key (where one level has tuple-valued entries), the dimension was incorrectly preserved because _is_nested_tuple() detected the nested tuples and used get_locs() which returns an array, instead of get_loc() which returns a scalar. The fix tries get_loc() first when a nested tuple is detected, falling back to get_locs() only if get_loc() fails (e.g., for slice-in-tuple multi-value selections). Fixes pydata#11341
…s None When a package is importable but has no version metadata (e.g., packages installed via QGIS's embedded Python), importlib.metadata.version() returns None. This caused a TypeError in Version(). Fixes pydata#11344
Contributor
|
Hi @C1-BA-B1-F3 . Thanks for taking the time to open PRs here. However, many of these issues already had existing open PRs, and it appears you are using AI agents to do it (I can't believe a new contributor can contribute to so many different areas of the codebase so quickly). You also appear to have open 2 PRs to fix the same issue :/ . Please refrain from doing so. We cannot keep up with this pace. |
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.
Problem
module_available()raisesTypeErrorwhenimportlib.metadata.version()returnsNonefor packages without proper version metadata (e.g., packages installed via QGIS's embedded Python).Fixes #11344
Root Cause
In
xarray/namedarray/utils.py,module_available()callsimportlib.metadata.version(module)which can returnNonefor packages without proper metadata. The result is passed directly toVersion()which expects a string.Fix
Add a
Nonecheck afterimportlib.metadata.version()and returnFalsewhen version metadata is unavailable (since we can't verify the minimum version requirement).Testing
Added regression test
test_module_available_with_none_versionthat mocksimportlib.metadata.versionto returnNoneand verifiesmodule_available()handles it gracefully.