Skip to content

Faulty 1D DOK indexing  #481

@sayandip18

Description

@sayandip18

Describe the bug
1D DOK arrays lets the user "access" elements at higher dimensions

To Reproduce

>>> import numpy as np; import sparse
>>> shape=(5,)
>>> density=0.2
>>> s = sparse.random(shape, density, format="dok")
>>> s
<DOK: shape=(5,), dtype=float64, nnz=1, fill_value=0.0>
>>> s[1]
0.0
>>> s[2]
0.0
>>> s[1,1]
<DOK: shape=(2,), dtype=float64, nnz=0, fill_value=0.0>
>>> s[1,1,1]
<DOK: shape=(3,), dtype=float64, nnz=0, fill_value=0.0>
>>> s[1,1,1,1]
<DOK: shape=(4,), dtype=float64, nnz=0, fill_value=0.0>
>>> s[1,1,1,1,1]
<DOK: shape=(5,), dtype=float64, nnz=0, fill_value=0.0>
>>> s[1,1,1,1,1,1]
<DOK: shape=(6,), dtype=float64, nnz=0, fill_value=0.0>
>>> s[3,4,5]
<DOK: shape=(3,), dtype=float64, nnz=1, fill_value=0.0>
# and so on

Expected behavior
Should give IndexingError

System

  • OS and version: Ubuntu 20.04
  • sparse version: master
  • NumPy version: 1.19.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions