Skip to content

Optimize add_bounds#627

Open
bouweandela wants to merge 2 commits intoxarray-contrib:mainfrom
bouweandela:optimize-add-bounds
Open

Optimize add_bounds#627
bouweandela wants to merge 2 commits intoxarray-contrib:mainfrom
bouweandela:optimize-add-bounds

Conversation

@bouweandela
Copy link
Copy Markdown
Contributor

@bouweandela bouweandela commented Mar 30, 2026

Simplify the code for adding bounds by avoiding adding and removing indexes. This code is also a bit faster than the original.

In [1]: import xarray as xr, cf_xarray

In [2]: airds = xr.tutorial.open_dataset("air_temperature")

In [3]: %timeit airds.cf.add_bounds("time")

results in

2.05 ms ± 37 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

with this branch and

3.36 ms ± 318 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

with the current main branch.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.80%. Comparing base (a9cebee) to head (f466765).
⚠️ Report is 97 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #627      +/-   ##
==========================================
+ Coverage   85.78%   92.80%   +7.01%     
==========================================
  Files          13       14       +1     
  Lines        2364     2403      +39     
  Branches      183        0     -183     
==========================================
+ Hits         2028     2230     +202     
+ Misses        303      173     -130     
+ Partials       33        0      -33     
Flag Coverage Δ
mypy ?
unittests 92.80% <100.00%> (-1.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant