Skip to content

Raise a clearer error when open_dataset is given a list of paths - #11526

Open
NoiceHax wants to merge 2 commits into
pydata:mainfrom
NoiceHax:fix/issue-6510
Open

Raise a clearer error when open_dataset is given a list of paths#11526
NoiceHax wants to merge 2 commits into
pydata:mainfrom
NoiceHax:fix/issue-6510

Conversation

@NoiceHax

Copy link
Copy Markdown
Contributor

Description

xr.open_dataset(["file1.nc", "file2.nc"]) failed with "did not find a match in any of xarray's currently installed IO backends", which sends you off checking whether one of the files is corrupt or whether a dependency is missing. The real problem is that the argument is a list and the user wants open_mfdataset.

guess_engine now spots a list or tuple and says that:

ValueError: open_dataset opens a single file, but got a list.
Use open_mfdataset to open multiple files as a single dataset.

The check sits at the end of guess_engine, next to the existing FileNotFoundError check and just before the generic ValueError. Every backend still gets a chance to claim the input first, so a third party backend that does accept a sequence keeps working. Only the path that was already failing changes.

Noice = "Noice" is added to the typos allowlist in pyproject.toml so the whats-new byline passes pre-commit.

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: Claude Code. The code and test were drafted with it, then I read the diff and ran the tests locally.

Passing a list or tuple of paths to open_dataset failed with the
generic "did not find a match in any of xarray's currently installed
IO backends" message, which does not hint at the actual mistake.

The check sits at the end of guess_engine, right after the existing
FileNotFoundError check, so backends that do accept a sequence still
get their chance to claim the input first.

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: raise more informative error message for xr.open_dataset(list_of_paths)

1 participant