Skip to content

triu and tril have wrong dtypes for some chunks in old version of numpy #7287

@bmerry

Description

@bmerry

What happened:

When using a version of numpy that doesn't implement the shape argument to zeros_like, the zero fill in triu and tril is always float.

What you expected to happen:

The computed chunks should all have the same dtype as the array itself, which should come from the input argument.

Minimal Complete Verifiable Example:

import numpy as np
import dask.array as da

x = da.ones((6, 6), chunks=2, dtype=np.int64)
t = da.triu(x)
chunk = t[4:6, 0:2]
print(chunk.compute().dtype)

Prints float64 on numpy 1.15.1, but int64 (correct) on numpy 1.20.1.

Anything else we need to know?:

It's caused by the fallback code in zeros_like_safe, which ignores the dtype. There is a fix for this in #7277, but I thought I should file it as a separate bug for changelog tracking purposes. The fix is largely independent of the rest of #7227, so let me know if you'd like it cherry-picked into a separate PR.

#6997 might also fix it in passing.

Environment:

  • Dask version: master (d540d73)
  • Python version: 3.8
  • Operating System: Ubuntu 20.04
  • Install method (conda, pip, source): source

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions