Skip to content

Fix query on coordinate-only datasets - #11798

Merged
dcherian merged 2 commits into
pydata:mainfrom
LJimmy007:fix/query-coordinates-only-6449
Oct 24, 2026
Merged

dcherian merged 2 commits into
pydata:mainfrom
LJimmy007:fix/query-coordinates-only-6449

Conversation

@LJimmy007

Copy link
Copy Markdown
Contributor

Description

Fixes #6449.

Dataset.query raises UndefinedVariableError when a dataset contains coordinates but no data variables. Pandas treats the existing Dataset resolver as empty in this case, so coordinate names are not resolved.

This change adds self.coords as a second resolver while keeping self first. This makes coordinate names available without changing the existing lookup precedence or Dataset length semantics. The existing query tests are extended to cover coordinate-only datasets, explicit dimension coordinates, and virtual dimension coordinates across the supported parsers and engines.

Validation:

  • 36 focused query tests passed.
  • The complete Dataset and DataArray test modules returned 1,238 passed, 19 skipped, 5 xfailed, and 2 xpassed.
  • Mypy and all applicable pre-commit checks for the changed files passed.
  • Full-repository pre-commit encountered an unrelated Windows line-ending cycle in pixi.toml; its Git-normalized content remains unchanged.

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: Codex (implementation, testing, and English drafting); GPT-6.1 Sol (independent review).

Task prompt (translated): "Complete pydata/xarray #6449 by fixing query for datasets that contain only coordinates."

The submitter personally reviewed the changes, approved the description, and supplied the explanation of the approach above.

[Submitted by Codex on behalf of Liang, Jingyi.]

Include coordinate names in the pandas resolver scope while retaining the
Dataset as the first resolver. Extend query coverage to coordinate-only
datasets and explicit and virtual dimension coordinates.

Co-authored-by: Codex <noreply@openai.com>
@dcherian dcherian added the plan to merge Final call for comments label Oct 23, 2026
@headtr1ck

Copy link
Copy Markdown
Collaborator

I like how LLMs are now just throwing out simple fixes for 5 year old issues. Thanks!

Include the upstream pandas 3.1 documentation fix from pydata#11796 while preserving the reviewed query contribution.

Co-authored-by: Codex <noreply@openai.com>
@LJimmy007

Copy link
Copy Markdown
Contributor Author

Merged the latest upstream main into this branch, preserving the query fix and bringing in the existing documentation fix from #11796. ReadTheDocs now passes: https://app.readthedocs.org/projects/xray/builds/35378608/

[Posted by Codex on behalf of Liang, Jingyi.]

@dcherian
dcherian merged commit 89873e1 into pydata:main Oct 24, 2026
49 checks passed
@welcome

welcome Bot commented Oct 24, 2026

Copy link
Copy Markdown

Congratulations on completing your first pull request! Welcome to Xarray! We are proud of you, and hope to see you again! celebration gif

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

Labels

plan to merge Final call for comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

query on coords only dataset fails

4 participants