pydata / pydata/sparse

API to change fill-value

Open
#297 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

support
Dominant language
Python
Stars
668
Forks
141
Avg merge
2d 8h
Merged PRs (30d)
4

Description

Hi!

This is an awesome package and I'm having fun using it to its full potential. Hopefully this is the right place for this. I'm having an issue where, after a series of boolean operations, my fill value becomes True and my data value becomes False. This limits my ability to do further calculations.

I have a sparse, boolean n x n x m array.

>>> import sparse as sp
>>> m = sp.COO(
...    coords=np.array([[0, 0, 0], [0, 0, 1],
...                     [0, 1, 0],
...                     [1, 0, 0],
...                     [1, 1, 0], [1, 1, 1],
...                     [2, 2, 1], 
...                     [3, 3, 0], [3, 3, 1]
...                     ]).T,
...    data=1,
...    shape=(4, 4, 2),
... )
>>> m
<COO: shape=(4, 4, 2), dtype=int64, nnz=9, fill_value=0>

I want to identify rows/columns where there is not any value that is present in all three coordinates by checking for the number of positions that have something present and then that this is less than the number of regions.

>>> pres = (m.sum(axis=1) > 0).sum(axis=1) < 2
>>> pres
<COO: shape=(4,), dtype=bool, nnz=3, fill_value=True>
>>> pres.todense()
array([False, False,  True, False])

If I try to do something like flip my fill value, then I just get a matrix of zeros

>>> pres.fill_value = 0
>>> pres
<COO: shape=(4,), dtype=bool, nnz=3, fill_value=0>
>>> pres.todense()
array([False, False,  False, False])

But, the fact that my array density flips seems like a possible bug, or at least a parameter I'd like more control over.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported COO example and trace how boolean reductions determine fill_value and stored data. Review the existing COO fill_value behavior and related tests or API entry points; done means a supported way to change the fill value preserves the correct dense result without turning valid values into zeros.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.