Skip to content

Don't import xarray to check isinstance, check if it's loaded instead - #12682

Merged
crusaderky merged 4 commits into
dask:mainfrom
psobolewskiPhD:patch-1
Nov 17, 2026
Merged

crusaderky merged 4 commits into
dask:mainfrom
psobolewskiPhD:patch-1

Conversation

@psobolewskiPhD

@psobolewskiPhD psobolewskiPhD commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

dask.array.core imports xarray unconditionally, only to check if the object is an xarray. xarray is an expensive library that imports pandas, costing ~0.7-1 s, so this is a wasted startup cost to dask.array consumers not using xarray.

Instead of import, check if xarray is loaded, if it's not loaded then the object can safely be considered not an xarray object.
Recently implemented this in napari here: napari/napari#9780
and a similar pattern is used though out the scientific python ecosystem.

  • Closes #xxxx
  • Tests added / passed
  • Passes pixi run lint

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Unit Test Results

See test report for an extended history of previous test failures. This is useful for diagnosing flaky tests.

     29 files  ±0       29 suites  ±0   6h 30m 41s ⏱️ - 9m 10s
 19 932 tests ±0   18 503 ✅ ±0   1 429 💤 ±0  0 ❌ ±0 
436 330 runs  ±0  384 862 ✅ +5  51 468 💤  - 5  0 ❌ ±0 

Results for commit df5db2a. ± Comparison against base commit 9c85cb7.

♻️ This comment has been updated with latest results.

@psobolewskiPhD

Copy link
Copy Markdown
Contributor Author

The remaining CI failures appear unrelated "pandas.errors.Pandas4Warning"

@crusaderky
crusaderky self-requested a review November 17, 2026 00:08

@crusaderky crusaderky left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you!

@crusaderky
crusaderky merged commit da08800 into dask:main Nov 17, 2026
37 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants