Skip to content

Don't pass reduction kwargs to coord_func in Coarsen reductions - #11938

Open
tushar-mahalya wants to merge 1 commit into
pydata:mainfrom
tushar-mahalya:fix-coarsen-coord-kwargs
Open

tushar-mahalya wants to merge 1 commit into
pydata:mainfrom
tushar-mahalya:fix-coarsen-coord-kwargs

Conversation

@tushar-mahalya

Copy link
Copy Markdown
Contributor

Description

Coarsen reductions forward their **kwargs to the reduction of every coordinate along a coarsened dimension, not just to the data reduction. So da.coarsen(time=2).sum(min_count=1) raises TypeError: nanmean() got an unexpected keyword argument 'min_count' as soon as da has a time coordinate. std(ddof=1) and reduce(np.std, ddof=1) fail the same way.

The kwargs are meant for the data reduction, and coord_func is configured separately, so I removed them from the two coordinate calls in DataArrayCoarsen and DatasetCoarsen. This follows the discussion in the issue, where the suggestion for passing arguments to coord_func is functools.partial.

One behaviour change: skipna no longer reaches the coordinates either. test_coarsen_skipna only passed skipna=False through to a coordinate because its variable was named x along dimension x, which made it the index coordinate. I renamed the variable to v so the test checks the data, which is what its comments describe. Coordinates are now reduced with their coord_func defaults.

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. It found the issue, wrote the fix, tests and a first draft of this description. I reviewed the diff and the reasoning, reproduced the bug and ran the tests myself.

[This PR was opened by Claude Code on behalf of Tushar Sharma, who reviewed and approved it.]

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataArrayCoarsen.reduce passes kwargs to coordinate function

1 participant