Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shuffle use pyarrow more broadly #8596

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion distributed/shuffle/_disk.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from __future__ import annotations

import contextlib
import io
import pathlib
import shutil
import threading
from collections.abc import Callable, Generator, Iterable
from contextlib import contextmanager
from typing import Any

from packaging.version import parse as parse_version
from toolz import concat

from distributed.metrics import context_meter, thread_time
Expand All @@ -18,6 +20,19 @@
from distributed.utils import Deadline, empty_context, log_errors, nbytes


def open_file(*args: Any, **kwargs: Any) -> io.IOBase:
open_file = open
try:
import pyarrow as pa

if parse_version(pa.__version__) >= parse_version("15.0.0"):

Check warning on line 28 in distributed/shuffle/_disk.py

View check run for this annotation

Codecov / codecov/patch

distributed/shuffle/_disk.py#L28

Added line #L28 was not covered by tests
# Only >15 support append mode
open_file = pa.OSFile

Check warning on line 30 in distributed/shuffle/_disk.py

View check run for this annotation

Codecov / codecov/patch

distributed/shuffle/_disk.py#L30

Added line #L30 was not covered by tests
except ModuleNotFoundError:
pass
return open_file(*args, **kwargs)


class ReadWriteLock:
_condition: threading.Condition
_n_reads: int
Expand Down Expand Up @@ -177,7 +192,7 @@
if self._closed:
raise RuntimeError("Already closed")

with open(self.directory / str(id), mode="ab") as f:
with open_file(str(self.directory / str(id)), mode="ab") as f:
f.writelines(frames)

context_meter.digest_metric("disk-write", 1, "count")
Expand Down
4 changes: 2 additions & 2 deletions distributed/shuffle/_shuffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ def split_by_partition(
Split data into many arrow batches, partitioned by final partition
"""
import numpy as np
import pyarrow as pa

partitions = t.select([column]).to_pandas()[column].unique()
partitions.sort()
partitions = np.array(pa.compute.unique(t[column]).sort())
Copy link
Member

@hendrikmakait hendrikmakait Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid the remainder of the np conversion as well by leveraging pa.compute.(not)_equal and pa.compute.indices_nonzero?

t = t.sort_by(column)

partition = np.asarray(t[column])
Expand Down
Loading