nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: dask/dask
Pull request #6457 (2020-07-24 22:54:53)

Implement `sizeof` for some `bytes`-like objects
As it appears we don't actually support `sizeof` for `bytes`-like types [on PyPy]( https://github.com/dask/dask/blob/326a12a940f815d27ecf3afac623927a17c1c83b/dask/sizeof.py#L7 ), but they are easy to implement and commonly encountered, go ahead and implement custom `sizeof` for these `bytes`-like types.

- [x] Tests added / passed
- [x] Passes `black dask` / `flake8 dask`


mrocklin: +1
gforsyth: @jakirkham -- can you rebase against / merge from master so we can pick up the parquet test fixes?
jakirkham: Thanks for the ping. Yep, merged with `master`. 🙂
jakirkham: Looks like CI is now happy 💚

Patch:
diff --git a/dask/sizeof.py b/dask/sizeof.py
index c321990bc..4728f3820 100644
--- a/dask/sizeof.py
+++ b/dask/sizeof.py
@@ -1,5 +1,6 @@
 import random
 import sys
+from array import array
 from distutils.version import LooseVersion
 
 from .utils import Dispatch
@@ -21,6 +22,22 @@ def sizeof_default(o):
     return getsizeof(o)
 
 
+@sizeof.register(bytes)
+@sizeof.register(bytearray)
+def sizeof_bytes(o):
+    return len(o)
+
+
+@sizeof.register(memoryview)
+def sizeof_memoryview(o):
+    return o.nbytes
+
+
+@sizeof.register(array)
+def sizeof_array(o):
+    return o.itemsize * len(o)
+
+
 @sizeof.register(list)
 @sizeof.register(tuple)
 @sizeof.register(set)


Test patch:
diff --git a/dask/tests/test_sizeof.py b/dask/tests/test_sizeof.py
index 912da2f95..7e88b904f 100644
--- a/dask/tests/test_sizeof.py
+++ b/dask/tests/test_sizeof.py
@@ -1,4 +1,5 @@
 import sys
+from array import array
 
 import pytest
 
@@ -18,6 +19,13 @@ def test_containers():
     assert sizeof([1, 2, [3]]) > (getsizeof(3) * 3 + getsizeof([]))
 
 
+def test_bytes_like():
+    assert 1000 <= sizeof(bytes(1000)) <= 2000
+    assert 1000 <= sizeof(bytearray(1000)) <= 2000
+    assert 1000 <= sizeof(memoryview(bytes(1000))) <= 2000
+    assert 8000 <= sizeof(array("d", range(1000))) <= 9000
+
+
 def test_numpy():
     np = pytest.importorskip("numpy")
     assert 8000 <= sizeof(np.empty(1000, dtype="f8")) <= 9000
Repository: dask/dask
Pull request #9388 (2022-08-17 13:59:03)

Add `entry_points` compatibility utility
In dask/dask#9283 @douglasdavis is using `importlib.metadata.entry_points` rather than `pkg_resources.iter_entry_points` because `pkg_resources` is part of `setuptools` and cannot be guaranteed to be installed. `importlib.metadata` is in the standard library and can be relied on.

However `importlib.metadata.entry_points` changed a bunch in 3.10 so some compatibility code is needed to support 3.8/3.9. 

Given that entrypoints are not only used in dask/dask#9283 but also in `dask-ctl` and potentially in dask/dask-kubernetes#532 I thought it makes sense to put one compatibility utility into `dask/dask` for reuse in other places.

jacobtomlinson: Yes totally should, moved :)

Patch:
diff --git a/dask/compatibility.py b/dask/compatibility.py
index b156f60d0..451810805 100644
--- a/dask/compatibility.py
+++ b/dask/compatibility.py
@@ -1,3 +1,4 @@
+import importlib.metadata
 import sys
 
 from packaging.version import parse as parse_version
@@ -5,3 +6,19 @@ from packaging.version import parse as parse_version
 _PY_VERSION = parse_version(".".join(map(str, sys.version_info[:3])))
 
 _EMSCRIPTEN = sys.platform == "emscripten"
+
+
+def entry_points(group=None):
+    """Returns an iterable of entrypoints.
+
+    For compatibility with Python 3.8/3.9.
+    In 3.10 the return type changed from a dict to an ``importlib.metadata.EntryPoints``.
+    This compatibility utility can be removed once Python 3.10 is the minimum.
+    """
+    eps = importlib.metadata.entry_points()
+    if group:
+        try:
+            return eps.select(group=group)
+        except AttributeError:
+            return eps.get(group, [])
+    return eps


Test patch:
diff --git a/dask/tests/test_compatibility.py b/dask/tests/test_compatibility.py
new file mode 100644
index 000000000..175a94e71
--- /dev/null
+++ b/dask/tests/test_compatibility.py
@@ -0,0 +1,5 @@
+from dask.compatibility import entry_points
+
+
+def test_entry_points():
+    assert "pytest" in [ep.name for ep in entry_points(group="console_scripts")]
Repository: dask/dask
Pull request #9429 (2022-08-25 11:27:50)

`tmpfile` does not end files with period on empty extension
As it turns out, when not specifying an extension, `tmpfile` ends the filename with a period, which is discouraged on Windows (https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file) and caused issues fixed in dask/distributed#6954 as other system utilities strip the period away.

- [ ] Tests added / passed
- [x] Passes `pre-commit run --all-files`

gjoseph92: I'm not familiar enough with dask's CI to know if these failures are flaky, or if this actually broke something?
* `dask/bytes/tests/test_http.py::test_parquet[fastparquet]` (this is failing everywhere so it's probably actually broken)
* `dask/tests/test_distributed.py::test_blockwise_dataframe_io[True-True-hdf]`
* `dask/tests/test_distributed.py::test_blockwise_dataframe_io[True-None-hdf]`
ian-r-rose: > dask/tests/test_distributed.py::test_blockwise_dataframe_io[True-True-hdf]

This looks like #8816, a known flaky test related to HDF5 and distributed disagreeing about whether something is locked.
hendrikmakait: `dask/bytes/tests/test_http.py::test_parquet[fastparquet]` looks like #9424
jrbourbeau: Just merged `main` which should fix the `test_parquet` failure 

Patch:
diff --git a/dask/utils.py b/dask/utils.py
index f24db9b73..a4665c63a 100644
--- a/dask/utils.py
+++ b/dask/utils.py
@@ -223,7 +223,9 @@ def tmpfile(extension="", dir=None):
     -----
     This context manager is particularly useful on Windows for opening temporary files multiple times.
     """
-    extension = "." + extension.lstrip(".")
+    extension = extension.lstrip(".")
+    if extension:
+        extension = "." + extension
     handle, filename = tempfile.mkstemp(extension, dir=dir)
     os.close(handle)
     os.remove(filename)


Test patch:
diff --git a/dask/tests/test_utils.py b/dask/tests/test_utils.py
index c3422c641..95e81f36c 100644
--- a/dask/tests/test_utils.py
+++ b/dask/tests/test_utils.py
@@ -43,6 +43,7 @@ from dask.utils import (
     stringify,
     stringify_collection_keys,
     takes_multiple_arguments,
+    tmpfile,
     typename,
 )
 from dask.utils_test import inc
@@ -888,3 +889,17 @@ def test_factors():
     assert factors(2) == {1, 2}
     assert factors(12) == {1, 2, 3, 4, 6, 12}
     assert factors(15) == {1, 3, 5, 15}
+
+
+def test_tmpfile_naming():
+    with tmpfile() as fn:
+        # Do not end file or directory name with a period.
+        #  This causes issues on Windows.
+        assert fn[-1] != "."
+
+    with tmpfile(extension="jpg") as fn:
+        assert fn[-4:] == ".jpg"
+
+    with tmpfile(extension=".jpg") as fn:
+        assert fn[-4:] == ".jpg"
+        assert fn[-5] != "."