Skip to content

argwhere doesn't work chunk-wise #10080

Closed

Description

@Dobatymo

Describe the issue:

argwhere doesn't work chunk-wise. Ie. it fully processes the input before it's starting to process it. The output in this case should be empty, since none of the elements are < 0. However it's still running out of memory trying to process the input.

Minimal Complete Verifiable Example:

from dask.diagnostics import ProgressBar
import dask.array as da
class DummyStore:
    def __setitem__(self, pos, item):
        print("store", pos)

with ProgressBar():
    arr = da.random.uniform(0, 1, size=(2000, 2000, 2000), chunks=(100, 100, 100)) < 0
    out = da.argwhere(arr)
    out.store(DummyStore())

Anything else we need to know?:

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "C:\Program Files\Python38\lib\site-packages\dask\array\core.py", line 1768, in store
    r = store([self], [target], **kwargs)
  File "C:\Program Files\Python38\lib\site-packages\dask\array\core.py", line 1236, in store
    compute_as_if_collection(Array, store_dsk, map_keys, **kwargs)
  File "C:\Program Files\Python38\lib\site-packages\dask\base.py", line 341, in compute_as_if_collection
    return schedule(dsk2, keys, **kwargs)
  File "C:\Program Files\Python38\lib\site-packages\dask\threaded.py", line 89, in get
    results = get_async(
  File "C:\Program Files\Python38\lib\site-packages\dask\local.py", line 511, in get_async
    raise_exception(exc, tb)
  File "C:\Program Files\Python38\lib\site-packages\dask\local.py", line 319, in reraise
    raise exc
  File "C:\Program Files\Python38\lib\site-packages\dask\local.py", line 224, in execute_task
    result = _execute_task(task, data)
  File "C:\Program Files\Python38\lib\site-packages\dask\core.py", line 119, in _execute_task
    return func(*(_execute_task(a, cache) for a in args))
  File "C:\Program Files\Python38\lib\site-packages\dask\array\chunk.py", line 427, in getitem
    result = result.copy()
numpy.core._exceptions.MemoryError: Unable to allocate 31.7 MiB for an array with shape (25, 1000, 166) and data type int64

Environment:

  • Dask version: 2023.3.1
  • Python version: 3.8.10
  • Operating System: Windows 10
  • Install method (conda, pip, source): pip

Activity

  1. added
    needs triage
    on Mar 17, 2023
  2. added
    bug
    and removed
    needs triage
    on Mar 21, 2023
  3. j-bennet commented on Mar 22, 2023

    @j-bennet
    Contributor

    @Dobatymo Thank you for the report. I tried your reproducible example, and while for me it completed and correctly returned an empty list, it did take an inordinate amount of memory. This deserves a closer look.

  4. added
    needs attention
    on Apr 24, 2023
  5. Dobatymo commented on Jun 18, 2025

    @Dobatymo
    Author

    @phofl this is still not fixed in dask==2025.5.1.

    Running the original snippet yields an error. My machine has 64GB of memory. It should definitely run this when chunked correctly.

    Traceback (most recent call last):
      File "...\dask-memory-error.py", line 10, in <module>
        out.store(DummyStore())
      File "...\Python312\Lib\site-packages\dask\array\core.py", line 1795, in store
        return store([self], [target], **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "...\Python312\Lib\site-packages\dask\array\core.py", line 1227, in store
        dask.compute(arrays, **kwargs)
      File "...\Python312\Lib\site-packages\dask\base.py", line 681, in compute
        results = schedule(expr, keys, **kwargs)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "...\Python312\Lib\site-packages\dask\array\core.py", line 5485, in concatenate3
        result = np.empty(shape=shape, dtype=dtype(deepfirst(arrays)))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    numpy.core._exceptions._ArrayMemoryError: Unable to allocate 127. MiB for an array with shape (100, 500, 334) and data type int64
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arraybugneeds attention

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions