Skip to content

Usage: confused by np.where behaviour and fill_value #871

Open
@dcherian

Description

@dcherian

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions