TomAugspurger: Thanks. I think you're missing a `.utils` in your test.

I think what you have (directly testing to_keys against client.scatter) is about as good as we could do. I never came up with an easy way to test it using GridSearchCV itself.

w.r.t. using `type(x).__name__`, that might be a bit better. We *might* be able to get a pandas DataFrame here.
lesteve: Done. I also test pandas Dataframe now.
diff --git a/dask_ml/model_selection/utils.py b/dask_ml/model_selection/utils.py
index eab9c80f..4972cffd 100644
--- a/dask_ml/model_selection/utils.py
+++ b/dask_ml/model_selection/utils.py
@@ -85,7 +85,7 @@ def to_keys(dsk, *args):
             yield x.key
         else:
             assert not is_dask_collection(x)
-            key = "array-" + tokenize(x)
+            key = type(x).__name__ + "-" + tokenize(x)
             dsk[key] = x
             yield key
 

GridsearchCV with prescattered data
During a recent debug session with @TomAugspurger we thought that dask-ml could take advantage of data which was pre-scattered:

> client.scatter(data, broadcast=True)

Current understanding is that dask-ml will not take advantage of pre-scatter data as the call to `KFold` will chop up data and not see the cached data on the workers.
diff --git a/tests/test_model_selection.py b/tests/test_model_selection.py
index 09a5da87..4afecad4 100644
--- a/tests/test_model_selection.py
+++ b/tests/test_model_selection.py
@@ -1,6 +1,10 @@
+import numpy as np
 from scipy import stats
+import pandas as pd
 from sklearn.svm import SVC
 
+from dask.distributed import Client
+
 import dask_ml.model_selection as dms
 
 
@@ -14,3 +18,14 @@ def test_search_basic(xy_classification):
     param_dist = {"C": stats.uniform}
     b = dms.RandomizedSearchCV(SVC(kernel="rbf", gamma=0.1), param_dist)
     b.fit(X, y)
+
+
+def test_to_keys_numpy_array():
+    rng = np.random.RandomState(0)
+    arr = rng.randn(20, 30)
+    df = pd.DataFrame(data=arr)
+    dsk = {}
+    grid_search_keys = list(dms.utils.to_keys(dsk, arr, df))
+    with Client() as client:
+        data_futures = client.scatter([arr, df])
+    assert grid_search_keys == [f.key for f in data_futures]

pip install -e .[complete]
parse_log_pytest
requirements.txt
pytest pytest-mock
apt-get update apt-get install -y gcc
3.7
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
absl-py==2.1.0
astunparse==1.6.3
cachetools==5.5.2
certifi @ file:///croot/certifi_1671487769961/work/certifi
charset-normalizer==3.4.1
click==8.1.8
cloudpickle==2.2.1
dask==2022.2.0
dask-glm==0.3.2
-e git+https://github.com/dask/dask-ml.git@42cf33b9ebed3535437426323ade63538d0dbbf1#egg=dask_ml
dask-tensorflow==0.0.2
dask-xgboost==0.2.0
distributed==2022.2.0
exceptiongroup==1.2.2
flatbuffers==25.2.10
fsspec==2023.1.0
gast==0.4.0
google-auth==2.38.0
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
grpcio==1.62.3
h5py==3.8.0
HeapDict==1.0.1
idna==3.10
importlib-metadata==6.7.0
iniconfig==2.0.0
Jinja2==3.1.6
joblib==1.3.2
keras==2.11.0
libclang==18.1.1
llvmlite==0.39.1
locket==1.0.0
Markdown==3.4.4
MarkupSafe==2.1.5
msgpack==1.0.5
multipledispatch==1.0.0
numba==0.56.4
numpy==1.21.6
oauthlib==3.2.2
opt-einsum==3.3.0
packaging==24.0
pandas==1.3.5
partd==1.4.1
pluggy==1.2.0
protobuf==3.19.6
psutil==7.0.0
pyasn1==0.5.1
pyasn1-modules==0.3.0
pytest==7.4.4
pytest-mock==3.11.1
python-dateutil==2.9.0.post0
pytz==2025.2
PyYAML==6.0.1
requests==2.31.0
requests-oauthlib==2.0.0
rsa==4.9
scikit-learn==1.0.2
scipy==1.7.3
six==1.17.0
sortedcontainers==2.4.0
sparse==0.13.0
tblib==2.0.0
tensorboard==2.11.2
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
tensorflow==2.11.0
tensorflow-estimator==2.11.0
tensorflow-io-gcs-filesystem==0.34.0
termcolor==2.3.0
threadpoolctl==3.1.0
tomli==2.0.1
toolz==0.12.1
tornado==6.2
typing_extensions==4.7.1
urllib3==2.0.7
Werkzeug==2.2.3
wrapt==1.16.0
xgboost==0.90
zict==2.2.0
zipp==3.15.0

name: dask-ml
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - absl-py==2.1.0
      - astunparse==1.6.3
      - cachetools==5.5.2
      - charset-normalizer==3.4.1
      - click==8.1.8
      - cloudpickle==2.2.1
      - dask==2022.2.0
      - dask-glm==0.3.2
      - dask-tensorflow==0.0.2
      - dask-xgboost==0.2.0
      - distributed==2022.2.0
      - exceptiongroup==1.2.2
      - flatbuffers==25.2.10
      - fsspec==2023.1.0
      - gast==0.4.0
      - google-auth==2.38.0
      - google-auth-oauthlib==0.4.6
      - google-pasta==0.2.0
      - grpcio==1.62.3
      - h5py==3.8.0
      - heapdict==1.0.1
      - idna==3.10
      - importlib-metadata==6.7.0
      - iniconfig==2.0.0
      - jinja2==3.1.6
      - joblib==1.3.2
      - keras==2.11.0
      - libclang==18.1.1
      - llvmlite==0.39.1
      - locket==1.0.0
      - markdown==3.4.4
      - markupsafe==2.1.5
      - msgpack==1.0.5
      - multipledispatch==1.0.0
      - numba==0.56.4
      - numpy==1.21.6
      - oauthlib==3.2.2
      - opt-einsum==3.3.0
      - packaging==24.0
      - pandas==1.3.5
      - partd==1.4.1
      - pluggy==1.2.0
      - protobuf==3.19.6
      - psutil==7.0.0
      - pyasn1==0.5.1
      - pyasn1-modules==0.3.0
      - pytest==7.4.4
      - pytest-mock==3.11.1
      - python-dateutil==2.9.0.post0
      - pytz==2025.2
      - pyyaml==6.0.1
      - requests==2.31.0
      - requests-oauthlib==2.0.0
      - rsa==4.9
      - scikit-learn==1.0.2
      - scipy==1.7.3
      - six==1.17.0
      - sortedcontainers==2.4.0
      - sparse==0.13.0
      - tblib==2.0.0
      - tensorboard==2.11.2
      - tensorboard-data-server==0.6.1
      - tensorboard-plugin-wit==1.8.1
      - tensorflow==2.11.0
      - tensorflow-estimator==2.11.0
      - tensorflow-io-gcs-filesystem==0.34.0
      - termcolor==2.3.0
      - threadpoolctl==3.1.0
      - tomli==2.0.1
      - toolz==0.12.1
      - tornado==6.2
      - typing-extensions==4.7.1
      - urllib3==2.0.7
      - werkzeug==2.2.3
      - wrapt==1.16.0
      - xgboost==0.90
      - zict==2.2.0
      - zipp==3.15.0
prefix: /opt/conda/envs/dask-ml

tests/test_model_selection.py::test_to_keys_numpy_array
tests/test_model_selection.py::test_search_basic
dask_ml/model_selection/utils.py
dask_ml/model_selection/utils.py