Skip to content

Fix the dask-ml example when running with 2.2.3 #314

@c-bata

Description

@c-bata

Expected behavior

After the release of numpy 2.2.3, the CI related to dask-ml started failing. To temporarily resolve the issue, I opened a PR to add the version constraint. This issue proposes resolving the failure.

Environment

See https://github.com/optuna/optuna-examples/actions/runs/14430672438/job/40465062134

Error messages, stack traces, or logs

[W 2025-04-13 15:42:28,803] Trial 0 failed with parameters: {'solver': 'proximal_grad', 'C': 0.7797059183107912, 'penalty': 'l2'} because of 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.').
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.9/x64/lib/python3.12/site-packages/optuna/study/_optimize.py", line 197, in _run_trial
    value_or_values = func(trial)
                      ^^^^^^^^^^^
  File "/home/runner/work/optuna-examples/optuna-examples/dask_ml/dask_ml_simple.py", line 39, in objective
    classifier.fit(X_train, y_train)
  File "/opt/hostedtoolcache/Python/3.12.9/x64/lib/python3.12/site-packages/dask_ml/linear_model/glm.py", line 189, in fit
    self._coef = algorithms._solvers[self.solver](X, y, **solver_kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.9/x64/lib/python3.12/site-packages/dask_glm/utils.py", line 32, in normalize_inputs
    out = algo(Xn, y, *args, **kwargs).copy()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.9/x64/lib/python3.12/site-packages/dask_glm/algorithms.py", line 461, in proximal_grad
    beta = zeros(shape=p, arr=getattr(X, "_meta", None))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.9/x64/lib/python3.12/site-packages/dask_glm/utils.py", line 43, in zeros
    if arr:
       ^^^
ValueError: The truth value of an empty array is ambiguous. Use `array.size > 0` to check that an array is not empty.
[W 2025-04-13 [15](https://github.com/optuna/optuna-examples/actions/runs/14430672438/job/40465062134#step:5:16):42:28,804] Trial 0 failed with value None.
Traceback (most recent call last):
  File "/home/runner/work/optuna-examples/optuna-examples/dask_ml/dask_ml_simple.py", line 47, in <module>
    study.optimize(objective, n_trials=100)
  File "/opt/hostedtoolcache/Python/3.12.9/x64/lib/python3.12/site-packages/optuna/study/study.py", line 475, in optimize
    _optimize(
  File "/opt/hostedtoolcache/Python/3.12.9/x64/lib/python3.12/site-packages/optuna/study/_optimize.py", line 63, in _optimize
    _optimize_sequential(
  File "/opt/hostedtoolcache/Python/3.12.9/x64/lib/python3.12/site-packages/optuna/study/_optimize.py", line [16](https://github.com/optuna/optuna-examples/actions/runs/14430672438/job/40465062134#step:5:17)0, in _optimize_sequential
    frozen_trial = _run_trial(study, func, catch)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.9/x64/lib/python3.12/site-packages/optuna/study/_optimize.py", line 248, in _run_trial
    raise func_err
  File "/opt/hostedtoolcache/Python/3.12.9/x64/lib/python3.12/site-packages/optuna/study/_optimize.py", line 197, in _run_trial
    value_or_values = func(trial)
                      ^^^^^^^^^^^
  File "/home/runner/work/optuna-examples/optuna-examples/dask_ml/dask_ml_simple.py", line 39, in objective
    classifier.fit(X_train, y_train)
  File "/opt/hostedtoolcache/Python/3.12.9/x64/lib/python3.12/site-packages/dask_ml/linear_model/glm.py", line [18](https://github.com/optuna/optuna-examples/actions/runs/14430672438/job/40465062134#step:5:19)9, in fit
    self._coef = algorithms._solvers[self.solver](X, y, **solver_kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.9/x64/lib/python3.12/site-packages/dask_glm/utils.py", line 32, in normalize_inputs
    out = algo(Xn, y, *args, **kwargs).copy()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.9/x64/lib/python3.12/site-packages/dask_glm/algorithms.py", line 461, in proximal_grad
    beta = zeros(shape=p, arr=getattr(X, "_meta", None))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.9/x64/lib/python3.12/site-packages/dask_glm/utils.py", line 43, in zeros
    if arr:
       ^^^
ValueError: The truth value of an empty array is ambiguous. Use `array.size > 0` to check that an array is not empty.
Error: Process completed with exit code 1.```

## Steps to reproduce

See the corresponding GitHub actions workflow file.

## Reproducible examples (optional)

See the corresponding GitHub actions workflow file.


```python
# python code

Additional context (optional)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue/PR about behavior that is broken. Not for typos/CI but for example itself.staleExempt from stale bot labeling.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions