nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: dask/dask
Pull request #5789 (2020-01-14 19:48:50)

Update order to handle empty task graph
This is a follow-up to https://github.com/dask/dask/pull/5646 which allows us to maintain backwards compatibility when dealing with empty task graphs.

On the latest release (2.9.1), we have:

```python
In [1]: import dask

In [2]: dask.__version__
Out[2]: '2.9.1'

In [3]: dask.order.order({})
Out[3]: {}
```

while on the current `master`, we have:

```python
In [1]: import dask

In [2]: dask.order.order({})
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-32827a593ec3> in <module>
----> 1 dask.order.order({})

~/github/dask/dask/dask/order.py in order(dsk, dependencies)
    232
    233     is_init_sorted = False
--> 234     item = min(init_stack, key=initial_stack_key)
    235     while True:
    236         outer_stack_append(item)

ValueError: min() arg is an empty sequence
```

For reference, this came up in the `distributed` test suite where several tests pass empty graphs to `order()`

- [x] Tests added / passed
- [ ] Passes `black dask` / `flake8 dask`



Patch:
diff --git a/dask/order.py b/dask/order.py
index 8abf24789..8aad68d7b 100644
--- a/dask/order.py
+++ b/dask/order.py
@@ -102,6 +102,9 @@ def order(dsk, dependencies=None):
     >>> order(dsk)
     {'a': 0, 'c': 1, 'b': 2, 'd': 3}
     """
+    if not dsk:
+        return {}
+
     if dependencies is None:
         dependencies = {k: get_dependencies(dsk, k) for k in dsk}
 


Test patch:
diff --git a/dask/tests/test_order.py b/dask/tests/test_order.py
index f16d28527..98e450f48 100644
--- a/dask/tests/test_order.py
+++ b/dask/tests/test_order.py
@@ -652,3 +652,7 @@ def test_order_cycle():
         order({"a": (f, "b"), "b": (f, "c"), "c": (f, "a", "d"), "d": 1})
     with pytest.raises(RuntimeError, match="Cycle detected"):
         order({"a": (f, "b"), "b": (f, "c"), "c": (f, "a", "d"), "d": (f, "b")})
+
+
+def test_order_empty():
+    assert order({}) == {}
Repository: dask/dask
Pull request #5812 (2020-01-21 15:24:53)

Fix check on dataclass instances in unpack_collections
This fixes a crash when encountering a dataclass type object (not an instance):

```python
File "/code/.venv/lib/python3.7/site-packages/dask/base.py", line 315, in unpack_collections
    ...
File "/code/.venv/lib/python3.7/site-packages/dask/base.py", line 304, in <listcomp>
    for f in dataclass_fields(expr)
AttributeError: type object 'MyClass' has no attribute 'example'
```

From the [dataclasses docs](https://docs.python.org/3.7/library/dataclasses.html#dataclasses.is_dataclass):

> If you need to know if a class is an instance of a dataclass (and not a dataclass itself), then add a further check for `not isinstance(obj, type)`

- [x] Tests added / passed
- [x] Passes `black dask` / `flake8 dask`


TomAugspurger: Thanks, can you add a test that hits this case?

Patch:
diff --git a/dask/base.py b/dask/base.py
index 506927900..cb2c17e6b 100644
--- a/dask/base.py
+++ b/dask/base.py
@@ -292,7 +292,7 @@ def unpack_collections(*args, **kwargs):
                 tsk = (typ, [_unpack(i) for i in expr])
             elif typ in (dict, OrderedDict):
                 tsk = (typ, [[_unpack(k), _unpack(v)] for k, v in expr.items()])
-            elif is_dataclass(expr):
+            elif is_dataclass(expr) and not isinstance(expr, type):
                 tsk = (
                     apply,
                     typ,


Test patch:
diff --git a/dask/tests/test_base.py b/dask/tests/test_base.py
index 7f2f17cb0..e252bd383 100644
--- a/dask/tests/test_base.py
+++ b/dask/tests/test_base.py
@@ -456,6 +456,7 @@ def test_unpack_collections():
 
         if dataclasses is not None:
             t[2]["f"] = ADataClass(a=a)
+            t[2]["g"] = (ADataClass, a)
 
         return t
Repository: dask/dask
Pull request #5947 (2020-02-25 21:27:16)

Register deterministic tokenization for range objects
Currently our tokenization of `range` objects isn't deterministic. For example:

```python
from dask.base import tokenize

for _ in range(3):
    print(tokenize(range(5)))
```

outputs:

```
d424666834140c08de99b23f85a7b60c
a3a1bdd9013db6364668f1d224d4cac6
13142f6359eb57df2fc8230942f1ece9
```

This PR adds a deterministic tokenization for `range` objects based on their `start`, `stop`, and `step` attributes. With the changes in this PR, the above snippet outputs a consistent hash:

```
3b69507db0ea8dfcb39cfce774a1df29
3b69507db0ea8dfcb39cfce774a1df29
3b69507db0ea8dfcb39cfce774a1df29
```

- [ ] Tests added / passed
- [x] Passes `black dask` / `flake8 dask`


jrbourbeau: For reference, the test failures on the AppVeyor are unrelated to the changes in this PR (xref #5948) 

Patch:
diff --git a/dask/base.py b/dask/base.py
index 1612b8408..e3ac1e9d4 100644
--- a/dask/base.py
+++ b/dask/base.py
@@ -683,6 +683,11 @@ def normalize_literal(lit):
     return "literal", normalize_token(lit())
 
 
+@normalize_token.register(range)
+def normalize_range(r):
+    return list(map(normalize_token, [r.start, r.stop, r.step]))
+
+
 @normalize_token.register(object)
 def normalize_object(o):
     method = getattr(o, "__dask_tokenize__", None)


Test patch:
diff --git a/dask/tests/test_base.py b/dask/tests/test_base.py
index 663a77846..6f96e529d 100644
--- a/dask/tests/test_base.py
+++ b/dask/tests/test_base.py
@@ -394,6 +394,13 @@ def test_tokenize_ordered_dict():
     assert tokenize(a) != tokenize(c)
 
 
+def test_tokenize_range():
+    assert tokenize(range(5, 10, 2)) == tokenize(range(5, 10, 2))  # Identical ranges
+    assert tokenize(range(5, 10, 2)) != tokenize(range(1, 10, 2))  # Different start
+    assert tokenize(range(5, 10, 2)) != tokenize(range(5, 15, 2))  # Different stop
+    assert tokenize(range(5, 10, 2)) != tokenize(range(5, 10, 1))  # Different step
+
+
 @pytest.mark.skipif("not np")
 def test_tokenize_object_array_with_nans():
     a = np.array([u"foo", u"Jos\xe9", np.nan], dtype="O")
Repository: dask/dask
Pull request #6000 (2020-03-10 17:50:07)

gh-5999: set `rename_fused_keys` to `None` by default in bag.optimize
This fixes the issue where using `dask.config.set({"fuse_rename_keys": False})` has no effect for optimization of dask bags

- [x] Tests added / passed
- [x] Passes `black dask` / `flake8 dask`



Patch:
diff --git a/dask/bag/core.py b/dask/bag/core.py
index d5fd0856a..f2477b27e 100644
--- a/dask/bag/core.py
+++ b/dask/bag/core.py
@@ -155,7 +155,7 @@ def inline_singleton_lists(dsk, keys, dependencies=None):
     return dsk
 
 
-def optimize(dsk, keys, fuse_keys=None, rename_fused_keys=True, **kwargs):
+def optimize(dsk, keys, fuse_keys=None, rename_fused_keys=None, **kwargs):
     """ Optimize a dask from a dask Bag. """
     dsk = ensure_dict(dsk)
     dsk2, dependencies = cull(dsk, keys)


Test patch:
diff --git a/dask/bag/tests/test_bag.py b/dask/bag/tests/test_bag.py
index eb7b5f081..208289546 100644
--- a/dask/bag/tests/test_bag.py
+++ b/dask/bag/tests/test_bag.py
@@ -557,6 +557,20 @@ def test_inline_singleton_lists():
     assert inline_singleton_lists(inp, ["c"]) == inp
 
 
+def test_rename_fused_keys_bag():
+    inp = {"b": (list, "a"), "c": (f, "b", 1)}
+
+    outp = optimize(inp, ["c"], rename_fused_keys=False)
+    assert outp.keys() == {"c"}
+    assert outp["c"][1:] == ("a", 1)
+
+    with dask.config.set({"fuse_rename_keys": False}):
+        assert optimize(inp, ["c"]) == outp
+
+    # By default, fused keys are renamed
+    assert optimize(inp, ["c"]) != outp
+
+
 def test_take():
     assert list(b.take(2)) == [0, 1]
     assert b.take(2) == (0, 1)