Repository: dask/dask

Issue:
Tests for dummy data generation failing
Looks like there are some tests failing for the dummy data generation

https://dask.github.io/dask/test_short_report.html

https://github.com/dask/dask/actions/runs/7650514559/job/20846717103

Discussion:
github-actions[bot]: ## Unit Test Results
_See [test report](https://dask.github.io/dask/test_report.html) for an extended history of previous test failures. This is useful for diagnosing flaky tests._

     15 files  ±0       15 suites  ±0   3h 14m 23s :stopwatch: -22s
 12 985 tests ±0   12 016 :white_check_mark: ±0     923 :zzz: ±0    5 :x: ±0   41 :fire: ±0 
160 529 runs  ±0  143 239 :white_check_mark: +1  16 527 :zzz:  - 1  353 :x: ±0  410 :fire: ±0 

For more details on these failures and errors, see [this check](https://github.com/dask/dask/runs/21217078783).

Results for commit 84a4936f. ± Comparison against base commit daf1f7c7.

[test-results]:data:application/gzip;base64,H4sIAAOiwGUC/0XMTQ7CIBCG4as0rF0AM1DwMoZCSYj9MRRWxrs71rYsv2cy75vFNI0bu3dC3Tq21VTaCjW7ktblt4XWQETXst+lNercj616vyMXuuEzvQitvP4e0aWJqD2OOa+ZBAVRrsue1lxJe+wrjSCh4T8ttJL9aUcbFJzS4pzIr/OcCk1m0KEFHYeIGJD3TrsIodfRj94NykOQaIyQ7PMF1vQYsB4BAAA=


Patch:
diff --git a/continuous_integration/environment-3.10.yaml b/continuous_integration/environment-3.10.yaml
index d917a0781..82f301b36 100644
--- a/continuous_integration/environment-3.10.yaml
+++ b/continuous_integration/environment-3.10.yaml
@@ -23,7 +23,7 @@ dependencies:
   - pytest-xdist
   - moto<5
   # Optional dependencies
-  - mimesis<13.1.0  # https://github.com/dask/dask/issues/10858
+  - mimesis
   - numpy=1.23
   - pandas=1.5
   - numba<0.59.0  # Removed numba.generated_jit which pandas<2.1 uses
diff --git a/continuous_integration/environment-3.11.yaml b/continuous_integration/environment-3.11.yaml
index 16e5ab4ef..f15c8ea38 100644
--- a/continuous_integration/environment-3.11.yaml
+++ b/continuous_integration/environment-3.11.yaml
@@ -23,7 +23,7 @@ dependencies:
   - pytest-xdist
   - moto<5
   # Optional dependencies
-  - mimesis<13.1.0  # https://github.com/dask/dask/issues/10858
+  - mimesis
   - numpy
   - pandas
   - flask
diff --git a/continuous_integration/environment-3.12.yaml b/continuous_integration/environment-3.12.yaml
index dc8d248f2..c2a528358 100644
--- a/continuous_integration/environment-3.12.yaml
+++ b/continuous_integration/environment-3.12.yaml
@@ -23,7 +23,7 @@ dependencies:
   - pytest-xdist
   - moto<5
   # Optional dependencies
-  - mimesis<13.1.0  # https://github.com/dask/dask/issues/10858
+  - mimesis
   - numpy
   - pandas
   - flask
diff --git a/dask/array/routines.py b/dask/array/routines.py
index 8a5c0f922..0398567a0 100644
--- a/dask/array/routines.py
+++ b/dask/array/routines.py
@@ -2056,24 +2056,19 @@ def _isnonzero_vec(v):
 _isnonzero_vec = np.vectorize(_isnonzero_vec, otypes=[bool])
 
 
+def _isnonzero(a):
+    # Output of np.vectorize can't be pickled
+    return _isnonzero_vec(a)
+
+
 def isnonzero(a):
-    if a.dtype.kind in {"U", "S"}:
-        # NumPy treats all-whitespace strings as falsy (like in `np.nonzero`).
-        # but not in `.astype(bool)`. To match the behavior of numpy at least until
-        # 1.19, we use `_isnonzero_vec`. When NumPy changes behavior, we should just
-        # use the try block below.
-        # https://github.com/numpy/numpy/issues/9875
-        return a.map_blocks(_isnonzero_vec, dtype=bool)
+    """Handle special cases where conversion to bool does not work correctly.
+    xref: https://github.com/numpy/numpy/issues/9479
+    """
     try:
-        np.zeros(tuple(), dtype=a.dtype).astype(bool)
+        np.zeros([], dtype=a.dtype).astype(bool)
     except ValueError:
-        ######################################################
-        # Handle special cases where conversion to bool does #
-        # not work correctly.                                #
-        #                                                    #
-        # xref: https://github.com/numpy/numpy/issues/9479   #
-        ######################################################
-        return a.map_blocks(_isnonzero_vec, dtype=bool)
+        return a.map_blocks(_isnonzero, dtype=bool)
     else:
         return a.astype(bool)
 
diff --git a/dask/datasets.py b/dask/datasets.py
index 274fe7499..7912e4179 100644
--- a/dask/datasets.py
+++ b/dask/datasets.py
@@ -163,7 +163,7 @@ def make_people(npartitions=10, records_per_partition=1000, seed=None, locale="e
     )
 
     schema = lambda field: {
-        "age": field("person.age"),
+        "age": field("random.randint", a=0, b=120),
         "name": (field("person.name"), field("person.surname")),
         "occupation": field("person.occupation"),
         "telephone": field("person.telephone"),


Test patch:
diff --git a/dask/array/tests/test_routines.py b/dask/array/tests/test_routines.py
index 5a0e6f285..995f1f7c6 100644
--- a/dask/array/tests/test_routines.py
+++ b/dask/array/tests/test_routines.py
@@ -2,6 +2,7 @@ from __future__ import annotations
 
 import contextlib
 import itertools
+import pickle
 import sys
 import warnings
 from numbers import Number
@@ -2708,3 +2709,18 @@ def test_tril_triu_indices(n, k, m, chunks):
         )
     else:
         assert_eq(actual, expected)
+
+
+def test_pickle_vectorized_routines():
+    """Test that graphs that internally use np.vectorize can be pickled"""
+    a = da.from_array(["foo", "bar", ""])
+
+    b = da.count_nonzero(a)
+    assert_eq(b, 2, check_dtype=False)
+    b2 = pickle.loads(pickle.dumps(b))
+    assert_eq(b2, 2, check_dtype=False)
+
+    c = da.argwhere(a)
+    assert_eq(c, [[0], [1]], check_dtype=False)
+    c2 = pickle.loads(pickle.dumps(c))
+    assert_eq(c2, [[0], [1]], check_dtype=False)
diff --git a/dask/dataframe/tests/test_groupby.py b/dask/dataframe/tests/test_groupby.py
index f4bf2af39..2bdaa29af 100644
--- a/dask/dataframe/tests/test_groupby.py
+++ b/dask/dataframe/tests/test_groupby.py
@@ -2224,13 +2224,9 @@ def test_std_object_dtype(func):
 
 
 def test_std_columns_int():
-    # Make sure std() works when index_by is a df with integer column names
-    # Non regression test for issue #3560
-
     df = pd.DataFrame({0: [5], 1: [5]})
     ddf = dd.from_pandas(df, npartitions=2)
-    by = dask.array.from_array([0, 1]).to_dask_dataframe()
-    ddf.groupby(by).std()
+    assert_eq(ddf.groupby(ddf[0]).std(), df.groupby(df[0].copy()).std())
 
 
 def test_timeseries():
diff --git a/dask/tests/test_base.py b/dask/tests/test_base.py
index 273917687..f4d4c5323 100644
--- a/dask/tests/test_base.py
+++ b/dask/tests/test_base.py
@@ -427,7 +427,7 @@ def test_persist_dataframe():
     assert len(ddf1.__dask_graph__()) == 4
     ddf2 = ddf1.persist()
     assert isinstance(ddf2, dd.DataFrame)
-    assert len(ddf2.__dask_graph__()) == 2
+    assert len(ddf2.__dask_graph__()) == 2 if not dd._dask_expr_enabled() else 4
     dd.utils.assert_eq(ddf2, ddf1)
 
 
@@ -438,7 +438,7 @@ def test_persist_series():
     assert len(dds1.__dask_graph__()) == 4
     dds2 = dds1.persist()
     assert isinstance(dds2, dd.Series)
-    assert len(dds2.__dask_graph__()) == 2
+    assert len(dds2.__dask_graph__()) == 2 if not dd._dask_expr_enabled() else 4
     dd.utils.assert_eq(dds2, dds1)
 
 
@@ -452,7 +452,7 @@ def test_persist_scalar():
     dds2 = dds1.persist()
     if not dd._dask_expr_enabled():
         assert isinstance(dds2, dd.core.Scalar)
-    assert len(dds2.__dask_graph__()) == 1
+    assert len(dds2.__dask_graph__()) == 1 if not dd._dask_expr_enabled() else 2
     dd.utils.assert_eq(dds2, dds1)