Skip to content

BUG: round_trip_pickle for lib.no_default #40684

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

Merged
merged 1 commit into from
Mar 30, 2021
Merged
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
10 changes: 9 additions & 1 deletion pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import abc
from decimal import Decimal
from enum import Enum
import warnings

import cython
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/libs/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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