Skip to content

Commit 9dd2a3a

Browse files
committed
use ddf no_default instead of pd_no_default
pandas-dev/pandas#40397 (comment)
1 parent 4ed6290 commit 9dd2a3a

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

dask/dataframe/core.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
is_numeric_dtype,
1717
is_datetime64_any_dtype,
1818
)
19-
from pandas._libs.lib import no_default as pd_no_default
2019
from tlz import merge, first, unique, partition_all, remove
2120

2221
try:
@@ -1417,9 +1416,7 @@ def replace(self, to_replace=None, value=None, regex=False):
14171416
enforce_metadata=False,
14181417
)
14191418

1420-
def to_dask_array(
1421-
self, lengths=None, dtype=None, na_value=pd_no_default, meta=None
1422-
):
1419+
def to_dask_array(self, lengths=None, dtype=None, na_value=no_default, meta=None):
14231420
"""Convert a dask DataFrame to a dask array.
14241421
14251422
Parameters
@@ -1452,7 +1449,7 @@ def to_dask_array(
14521449
Returns
14531450
-------
14541451
"""
1455-
if not PANDAS_GT_110 and na_value is not pd_no_default:
1452+
if not PANDAS_GT_110 and na_value is not no_default:
14561453
raise NotImplementedError(
14571454
"na_value is not a valid argument for to_dask_array"
14581455
f"if pandas < 1.1.0. Pandas version is {pd.__version__}"

dask/dataframe/methods.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44
import pandas as pd
55
from pandas.api.types import is_categorical_dtype, union_categoricals
6-
from pandas._libs.lib import no_default as pd_no_default
6+
from pandas.api.extensions import no_default as pd_no_default
77
from tlz import partition
88

99
from ._compat import PANDAS_GT_110
@@ -326,7 +326,19 @@ def size(x):
326326
return x.size
327327

328328

329-
def to_numpy(df, _dtype, na_value=pd_no_default):
329+
def to_numpy(df, _dtype, na_value):
330+
# callers use the "__no_default__" string instead of `pd_no_default`,
331+
# since `pd_no_default` isn't consistently pickleable or tokenizeable
332+
# https://github.com/pandas-dev/pandas/issues/40397
333+
from .core import no_default
334+
335+
try:
336+
if na_value == no_default: # `==` not `is`, since it could be pickled
337+
na_value = pd_no_default
338+
except Exception:
339+
# could be pd.NA, where __bool__ will raise an error
340+
pass
341+
330342
kwargs = {"dtype": _dtype, "copy": False}
331343
if PANDAS_GT_110:
332344
kwargs["na_value"] = na_value

0 commit comments

Comments
 (0)