From ec83fc22255b982adf260302abbb51254c468c18 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 29 Mar 2021 15:14:14 -0700 Subject: [PATCH] BUG: round_trip_pickle for lib.no_default --- pandas/_libs/lib.pyx | 10 +++++++++- pandas/tests/libs/test_lib.py | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 94a4d586b4f13..646b5a05afcad 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -1,5 +1,6 @@ from collections import abc from decimal import Decimal +from enum import Enum import warnings import cython @@ -2433,8 +2434,15 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=False, return objects +class NoDefault(Enum): + # We make this an Enum + # 1) because it round-trips through pickle correctly (see GH#40397) + # 2) because mypy does not understand singletons + no_default = "NO_DEFAULT" + + # Note: no_default is exported to the public API in pandas.api.extensions -no_default = object() # Sentinel indicating the default value. +no_default = NoDefault.no_default # Sentinel indicating the default value. @cython.boundscheck(False) diff --git a/pandas/tests/libs/test_lib.py b/pandas/tests/libs/test_lib.py index 0532de9998c5f..67bd5b309b634 100644 --- a/pandas/tests/libs/test_lib.py +++ b/pandas/tests/libs/test_lib.py @@ -206,3 +206,9 @@ def test_get_reverse_indexer(self): def test_cache_readonly_preserve_docstrings(): # GH18197 assert Index.hasnans.__doc__ is not None + + +def test_no_default_pickle(): + # GH#40397 + obj = tm.round_trip_pickle(lib.no_default) + assert obj is lib.no_default