Skip to content

Optimize add_bounds#627

Open
bouweandela wants to merge 1 commit intoxarray-contrib:mainfrom
bouweandela:optimize-add-bounds
Open

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

Conversation

@bouweandela
Copy link
Copy Markdown
Contributor

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

1.29 ms ± 12.9 μs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

with this branch and

2.78 ms ± 20.4 μ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

❌ Patch coverage is 50.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.08%. Comparing base (a9cebee) to head (35aee00).
⚠️ Report is 97 commits behind head on main.

Files with missing lines Patch % Lines
cf_xarray/helpers.py 50.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #627      +/-   ##
==========================================
+ Coverage   85.78%   87.08%   +1.29%     
==========================================
  Files          13       15       +2     
  Lines        2364     3220     +856     
  Branches      183      307     +124     
==========================================
+ Hits         2028     2804     +776     
- Misses        303      371      +68     
- Partials       33       45      +12     
Flag Coverage Δ
mypy 46.00% <0.00%> (+7.46%) ⬆️
unittests 92.84% <100.00%> (-1.15%) ⬇️

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