Skip to content

fix: handle None module in module_available#11358

Open
jaythehardcoder wants to merge 1 commit into
pydata:mainfrom
jaythehardcoder:fix/module-available-none
Open

fix: handle None module in module_available#11358
jaythehardcoder wants to merge 1 commit into
pydata:mainfrom
jaythehardcoder:fix/module-available-none

Conversation

@jaythehardcoder
Copy link
Copy Markdown

Description

Closes #11344.

module_available(None) crashes with AttributeError: 'NoneType' object has no attribute 'startswith' during version checks (e.g., in the rain-to-flood toolkit).

This adds an early return of False when module is None, and a regression test covering None input, valid modules, and minversion checks.

Checklist

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.
      Tools: Hermes Agent

Test Plan

  • uv run pytest xarray/tests/test_namedarray.py::test_module_available -v -> 1 passed
  • uv run pytest xarray/tests/test_namedarray.py -q -> all existing tests still pass

module_available(None) crashes with:
  AttributeError: 'NoneType' object has no attribute 'startswith'

Add an early return of False when module is None, and
a regression test covering None, valid modules, and
minversion checks.

Closes pydata#11344

Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added the topic-NamedArray Lightweight version of Variable label May 26, 2026
Copy link
Copy Markdown
Contributor

@Illviljan Illviljan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we get a None as input? This function does not allow anything else than str.
Is this an actual problem in xarray?

@jaythehardcoder
Copy link
Copy Markdown
Author

It happens when external tooling (like uv scripts / pip-run workflows) imports xarray. In some Python environments, importlib.metadata.entry_points() returns None for a specific group, which gets passed into module_available() as the module parameter — see issue #11344 for the exact traceback. The fix handles that edge case gracefully instead of crashing.

@Illviljan
Copy link
Copy Markdown
Contributor

No the traceback shows a string is input in that example.

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

Labels

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