dask / dask/dask-glm

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

Open
#109 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
78
Forks
47
PR merge metrics
No merged PRs in 30d

Description

**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**:

```python
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.

https://github.com/dask/dask-glm/blob/0c7059353a59a246d68c2a7ee54ec5b493a5e357/dask_glm/utils.py#L42-L46

The conditional in L43 should be updated to:
```py
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.