# Dask on Ray - use a function with a large closure

**URL:** <https://discuss.ray.io/t/dask-on-ray-use-a-function-with-a-large-closure/14526>\
**Category:** Uncategorized\
**Created:** [April 26, 2024, 4:48pm UTC](https://discuss.ray.io/t/dask-on-ray-use-a-function-with-a-large-closure/14526 "2024-04-26T16:48:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rcongiu](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/rcongiu/32/6052_2.png) [@rcongiu](https://discuss.ray.io/u/rcongiu)\
**Post date:** [April 26, 2024, 4:48pm UTC](https://discuss.ray.io/t/dask-on-ray-use-a-function-with-a-large-closure/14526/1 "2024-04-26T16:48:50Z")

</div>

Hello Ray Community,

I am evaluating Ray on a POC and I am having some performance issues when trying to work on a dask dataframe using a function with a large closure.

Specifically, I am trying to label encode a field

```python
    def encode_id(x: str) -> int:
        # This contains a closure of a large object
        return lbl_encoder.transform([x])[0]
    df["id_enc"] = df["id"].apply(encode_id, meta=("encoded_label", "int"))

```

I was reading about distributing large objects using scatter, like suggested here [Distributing heavy functions via closures · Issue #5503 · dask/dask · GitHub](https://github.com/dask/dask/issues/5503), but since I am using dask on ray, I am not sure how to get a reference to the dask client, since dask on ray docs states that you should not instantiate the dask client directly.

Any suggestion is welcome! Thank in advance.
