Skip to content

ValueError in dask_glm.utils.zeros with NumPy 2.x due to ambiguous truth value of empty array #109

@xlt208

Description

@xlt208

Describe the issue:
When running algorithms.admm() or algorithms.proximal_grad() from dask-glm with NumPy 2.x (e.g., 2.2.5), I encounter the following error:

ValueError: The truth value of an empty array is ambiguous. Use `array.size > 0` to check that an array is not empty.

Minimal Complete Verifiable Example:

from dask_glm import algorithms, datasets

X, y = datasets.make_regression(
    n_samples=200000, n_features=100, n_informative=5, chunksize=10000
)
b1 = algorithms.admm(X, y, max_iter=5)
b2 = algorithms.proximal_grad(X, y, max_iter=5)

Anything else we need to know?:
This appears to originate from the zeros() function in dask_glm/utils.py. In NumPy 2.x, evaluating if arr: is no longer valid when arr is an empty array. This breaks compatibility and causes the function to fail. See https://numpy.org/doc/stable/reference/arrays.ndarray.html.

def zeros(shape, arr=None, **kwargs):
if arr:
return np.zeros_like(arr, shape=shape, **kwargs)
else:
return np.zeros(shape=shape, **kwargs)

The conditional in L43 should be updated to:

if arr is not None and arr.size > 0:

Environment:

  • dask version: 2025.7.0
  • dask-glm version: 0.3.2
  • numpy version: 2.2.5
  • Python version: 3.13
  • Operating System: Windows/Linux
  • Install method (conda, pip, source): conda

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