Usage: confused by `np.where` behaviour and `fill_value`
Open
Nobody has claimed this yet.
documentation
- Dominant language
- Python
- Stars
- 668
- Forks
- 141
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 4
Description
Please provide a description of what you'd like to do.
More dependable fill_value preservation in where
Example Code
import sparse
import numpy as np
array = sparse.COO.from_numpy(np.eye(3), fill_value=0)
assert np.where(array == 1, np.nan, array).fill_value == 0 # passes
assert np.where(array < 1, np.nan, array).fill_value == 0 # fails, result fill_value is np.nan
For mask=array==1, mask.fill_value=False and the array's fill_value is preserved in the np.where call.
For mask=array<1, mask.fill_value=True and the array's fill_value is NOT preserved in the np.where call.
This kind of behaviour is hard to rely on in a library. Is it a bug?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two np.where examples from the issue with sparse.COO.from_numpy and compare the mask fill values. Trace the np.where entry point and its fill-value handling, then establish consistent preservation behavior and regression coverage for both comparisons.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100