Skip to content

BUG handle reductions over empty dimensions - #11972

Open
susmita9878 wants to merge 2 commits into
pydata:mainfrom
susmita9878:investigate-11554-emty-reductions
Open

susmita9878 wants to merge 2 commits into
pydata:mainfrom
susmita9878:investigate-11554-emty-reductions

Conversation

@susmita9878

Copy link
Copy Markdown

Summary

Fixes [#11554](#11554).

Previously, min, max, and median reductions could raise errors when the reduced dimension was empty. Datetime and timedelta mean and median reductions also had problematic behavior for empty dimensions.

This change ensures that empty reductions return the appropriate missing-value result for supported dtypes:

  • Numeric reductions return NaN.
  • Boolean min and max reductions return NaN with an object dtype.
  • Datetime and timedelta reductions return NaT.
  • Empty output dimensions are preserved, including their shape and dtype.
  • Dask-backed arrays retain lazy execution.

Implementation

  • Add a helper to handle empty reduction results.
  • Preserve output shape and keepdims behavior.
  • Handle chunked arrays without eagerly computing them.
  • Add regression tests covering NumPy and Dask arrays, supported dtypes, and empty output dimensions.

Testing

  • Added regression tests in xarray/tests/test_dataarray.py.
  • Focused tests passed across Python 3.12, 3.14, and 3.15.
  • Broader test run: 3,150 passed, 85 skipped, 13 xfailed, 5 xpassed.
  • Pre-commit checks passed.

@github-actions github-actions Bot added the topic-arrays related to flexible array support label Dec 2, 2026

This branch has not been deployed

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

Labels

topic-arrays related to flexible array support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant