Skip to content

Conversation

@peanutfun
Copy link
Contributor

What type of PR is this? (check all applicable)

  • πŸ’Ύ Refactor
  • πŸͺ„ Feature
  • 🐞 Bug Fix
  • πŸ”§ Optimization
  • πŸ“š Documentation
  • πŸ§ͺ Test
  • πŸ› οΈ Other

Related issues

  • None

Checklist

  • Code follows style guide
  • Tests added
  • Documented the changes

This adds sparse.interp, the sparse equivalent to numpy.interp. The latter does not work on sparse array types, so I decided to implement a "wrapper". It effectively calls numpy.interp on the array data and its fill value and returns the original data type.

This function should integrate nicely because numpy will automatically dispatch any call to numpy.interp to sparse.interp, if one of the arguments is a sparse array. This is explicitly tested.

@github-actions github-actions bot added the enhancement Indicates new feature requests label Nov 3, 2025
Copy link
Collaborator

@hameerabbasi hameerabbasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A large part of this PR LGTM. I have just one overarching comment: The tests should look more like the tests in test_coo.py.

@peanutfun
Copy link
Contributor Author

@hameerabbasi Thanks, but can you be a bit more specific? Do I understand correctly that you want a test that

  1. Creates a random (dense) array: x
  2. Creates a sparse copy of x: y
  3. Calls np.interp with x and y
  4. Ensures the results are equal

@hameerabbasi
Copy link
Collaborator

@hameerabbasi Thanks, but can you be a bit more specific? Do I understand correctly that you want a test that

1. Creates a random (dense) array: x

2. Creates a sparse copy of x: y

3. Calls `np.interp` with x and y

4. Ensures the results are equal

That's correct, yes.

@prady0t
Copy link
Collaborator

prady0t commented Nov 4, 2025

You can also move the test to sparse/numba_backend/tests/test_coo.py.

* Add shortcut for dense data to spare.interp
* Move test to test_coo.py
* Adjust test to compare sparse.interp to numpy.interp
* Add test case for complex data
* Use random test data
@peanutfun
Copy link
Contributor Author

@hameerabbasi I moved the test to test_coo.py and (hopefully) adapted it to the testing style there. I also slightly updated the function with a shortcut for dense input data, preserving the data type if x is not a sparse array.

Let me know if there is anything else I can do.

hameerabbasi
hameerabbasi previously approved these changes Nov 5, 2025
@hameerabbasi hameerabbasi enabled auto-merge (squash) November 5, 2025 09:54
@hameerabbasi
Copy link
Collaborator

Thanks @peanutfun, I appreciate the addition! Just waiting for CI. Would you like a new release?

@hameerabbasi
Copy link
Collaborator

@peanutfun The doctest and one other test need updates; would you be willing to make those changes?

auto-merge was automatically disabled November 5, 2025 10:03

Head branch was pushed to by a user without write access

@peanutfun
Copy link
Contributor Author

@hameerabbasi I hope I fixed it now! A new release would be awesome, but it's not urgent for me.

@hameerabbasi
Copy link
Collaborator

@peanutfun
Copy link
Contributor Author

@hameerabbasi Indeed! Apparently I did not run the doctests. How about now? 🀞

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 5, 2025

CodSpeed Performance Report

Merging #903 will degrade performances by 33.06%

Comparing peanutfun:add-interp (6e8ad0c) with main (3a2e703)

Summary

❌ 2 regressions
βœ… 338 untouched

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
❌ test_index_fancy[side=100-rank=1-format='coo'] 1.2 ms 1.4 ms -10.62%
❌ test_index_slice[side=100-rank=2-format='gcxs'] 1.8 ms 2.6 ms -33.06%

@hameerabbasi hameerabbasi enabled auto-merge (squash) November 5, 2025 12:12
@hameerabbasi hameerabbasi disabled auto-merge November 5, 2025 12:12
@hameerabbasi hameerabbasi merged commit 0d0121a into pydata:main Nov 5, 2025
16 of 18 checks passed
@hameerabbasi
Copy link
Collaborator

That worked, thanks @peanutfun!

@peanutfun
Copy link
Contributor Author

Thanks for the support! This was my first contribution here, and it was a very smooth and pleasant experience 😊

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

Labels

enhancement Indicates new feature requests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants