Fix module_available() crash when version metadata is missing#11422
Fix module_available() crash when version metadata is missing#11422C1-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
|
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. |
|
@dcherian Thanks for the honest feedback, and I understand the concern. To be clear about how these came about: each PR targets a specific, self-contained bug with a failing test, and I'm the one accountable for the code in each — they aren't mass-generated without review. I run the test suites locally before opening them. That said, I hear you that several of these areas already had open PRs or active discussion, and crowding the queue isn't helpful. I'll slow down on xarray contributions and focus on the ones that are clearly unowned or where I can add value, rather than overlapping existing work. Appreciate you taking the time to say it directly. |
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.