-
-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
P2P shuffle: pickle tiny buffers into monolithic bytes objects (#8321)
- Loading branch information
1 parent
a387b3b
commit 0dc9e88
Showing
10 changed files
with
94 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from distributed.shuffle._core import _mean_shard_size | ||
|
||
|
||
def test_mean_shard_size(): | ||
assert _mean_shard_size([]) == 0 | ||
assert _mean_shard_size([b""]) == 0 | ||
assert _mean_shard_size([b"123", b"45678"]) == 4 | ||
# Don't fully iterate over large collections | ||
assert _mean_shard_size([b"12" * n for n in range(1000)]) == 9 | ||
# Support any Buffer object | ||
assert _mean_shard_size([b"12", bytearray(b"1234"), memoryview(b"123456")]) == 4 | ||
# Recursion into lists or tuples; ignore int | ||
assert _mean_shard_size([(1, 2, [3, b"123456"])]) == 6 | ||
# Don't blindly call sizeof() on unexpected objects | ||
with pytest.raises(TypeError): | ||
_mean_shard_size([1.2]) | ||
with pytest.raises(TypeError): | ||
_mean_shard_size([{1: 2}]) | ||
|
||
|
||
def test_mean_shard_size_numpy(): | ||
"""Test that _mean_shard_size doesn't call len() on multi-byte data types""" | ||
np = pytest.importorskip("numpy") | ||
assert _mean_shard_size([np.zeros(10, dtype="u1")]) == 10 | ||
assert _mean_shard_size([np.zeros(10, dtype="u8")]) == 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters