Skip to content

Fix module_available() crash when version metadata is missing#11422

Open
C1-BA-B1-F3 wants to merge 2 commits into
pydata:mainfrom
C1-BA-B1-F3:fix/issue-11344-module-available-none-version
Open

Fix module_available() crash when version metadata is missing#11422
C1-BA-B1-F3 wants to merge 2 commits into
pydata:mainfrom
C1-BA-B1-F3:fix/issue-11344-module-available-none-version

Conversation

@C1-BA-B1-F3

Copy link
Copy Markdown

Problem

module_available() raises TypeError when importlib.metadata.version() returns None for packages without proper version metadata (e.g., packages installed via QGIS's embedded Python).

TypeError: expected string or bytes-like object, got 'NoneType'

Fixes #11344

Root Cause

In xarray/namedarray/utils.py, module_available() calls importlib.metadata.version(module) which can return None for packages without proper metadata. The result is passed directly to Version() which expects a string.

Fix

Add a None check after importlib.metadata.version() and return False when version metadata is unavailable (since we can't verify the minimum version requirement).

Testing

Added regression test test_module_available_with_none_version that mocks importlib.metadata.version to return None and verifies module_available() handles it gracefully.

C1-BA-B1-F3 and others added 2 commits June 26, 2026 22:05
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
@github-actions github-actions Bot added topic-indexing topic-NamedArray Lightweight version of Variable labels Jun 26, 2026
@dcherian

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic-indexing topic-NamedArray Lightweight version of Variable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Load failure (in rain to flood toolkit)

2 participants