Skip to content

Conversation

Copy link

Copilot AI commented Aug 31, 2025

This PR fixes an API inconsistency in the DataArray.integrate method where it used a dim parameter while all other related methods consistently use coord.

Problem

The API was inconsistent across differentiation and integration methods:

# These all use 'coord' parameter consistently
ds.differentiate(coord='x')
da.differentiate(coord='x') 
ds.integrate(coord='x')

# But this one used 'dim' - inconsistent!
da.integrate(dim='x')  # Should be coord='x'

As noted in the issue, this inconsistency is confusing because "it doesn't make sense to integrate or differentiate over a dim because a dim by definition has no information about the distance between grid points." The operation should be performed over coordinates, not dimensions.

Solution

Changed DataArray.integrate to use coord parameter for consistency:

  • Method signature: integrate(dim=...)integrate(coord=...)
  • Docstring: Updated parameter description and examples
  • Implementation: Updated internal call to pass coord parameter correctly
  • Tests: Updated unit test to use new parameter name

Backward Compatibility

Existing code using positional arguments continues to work unchanged:

da.integrate("x")  # Still works exactly the same

Only keyword argument usage changes:

da.integrate(dim="x")   # OLD - would now raise TypeError
da.integrate(coord="x") # NEW - correct usage

Result

All differentiation and integration methods now have consistent APIs:

ds.differentiate(coord='x')  # ✓
da.differentiate(coord='x')  # ✓
ds.integrate(coord='x')      # ✓
da.integrate(coord='x')      # ✓ Fixed!

This makes the API more intuitive and aligns with the principle that integration and differentiation operate on coordinates, not dimensions.

Fixes #1.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] DataArray.integrate has a 'dim' arg, but Dataset.integrate has a 'coord' arg Fix DataArray.integrate API inconsistency - change 'dim' parameter to 'coord' Aug 31, 2025
Copilot AI requested a review from srodif August 31, 2025 19:26
@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 5, 2025

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.

DataArray.integrate has a 'dim' arg, but Dataset.integrate has a 'coord' arg

2 participants