Skip to content

Commit e3984f6

Browse files
jbrockmendelvladu
authored andcommitted
BUG: round_trip_pickle for lib.no_default (pandas-dev#40684)
1 parent 3080dcf commit e3984f6

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pandas/_libs/lib.pyx

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections import abc
22
from decimal import Decimal
3+
from enum import Enum
34
import warnings
45

56
import cython
@@ -2433,8 +2434,15 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=False,
24332434
return objects
24342435

24352436

2437+
class NoDefault(Enum):
2438+
# We make this an Enum
2439+
# 1) because it round-trips through pickle correctly (see GH#40397)
2440+
# 2) because mypy does not understand singletons
2441+
no_default = "NO_DEFAULT"
2442+
2443+
24362444
# Note: no_default is exported to the public API in pandas.api.extensions
2437-
no_default = object() # Sentinel indicating the default value.
2445+
no_default = NoDefault.no_default # Sentinel indicating the default value.
24382446

24392447

24402448
@cython.boundscheck(False)

pandas/tests/libs/test_lib.py

+6
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,9 @@ def test_get_reverse_indexer(self):
206206
def test_cache_readonly_preserve_docstrings():
207207
# GH18197
208208
assert Index.hasnans.__doc__ is not None
209+
210+
211+
def test_no_default_pickle():
212+
# GH#40397
213+
obj = tm.round_trip_pickle(lib.no_default)
214+
assert obj is lib.no_default

0 commit comments

Comments
 (0)