Skip to content

Commit be1556c

Browse files
no_default (#30788)
1 parent a51a562 commit be1556c

File tree

15 files changed

+43
-49
lines changed

15 files changed

+43
-49
lines changed

doc/source/reference/extensions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ behaves correctly.
6969
api.indexers.check_bool_array_indexer
7070

7171

72-
The sentinel ``pandas.api.extensions._no_default`` is used as the default
72+
The sentinel ``pandas.api.extensions.no_default`` is used as the default
7373
value in some methods. Use an ``is`` comparison to check if the user
7474
provides a non-default value.

pandas/_libs/lib.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,14 +2232,14 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=0,
22322232
return objects
22332233

22342234

2235-
# Note: _no_default is exported to the public API in pandas.api.extensions
2236-
_no_default = object() #: Sentinel indicating the default value.
2235+
# Note: no_default is exported to the public API in pandas.api.extensions
2236+
no_default = object() #: Sentinel indicating the default value.
22372237

22382238

22392239
@cython.boundscheck(False)
22402240
@cython.wraparound(False)
22412241
def map_infer_mask(ndarray arr, object f, const uint8_t[:] mask, bint convert=1,
2242-
object na_value=_no_default, object dtype=object):
2242+
object na_value=no_default, object dtype=object):
22432243
"""
22442244
Substitute for np.vectorize with pandas-friendly dtype inference.
22452245
@@ -2270,7 +2270,7 @@ def map_infer_mask(ndarray arr, object f, const uint8_t[:] mask, bint convert=1,
22702270
result = np.empty(n, dtype=dtype)
22712271
for i in range(n):
22722272
if mask[i]:
2273-
if na_value is _no_default:
2273+
if na_value is no_default:
22742274
val = arr[i]
22752275
else:
22762276
val = na_value

pandas/api/extensions/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Public API for extending pandas objects."""
2-
from pandas._libs.lib import _no_default # noqa: F401
2+
from pandas._libs.lib import no_default # noqa: F401
33

44
from pandas.core.dtypes.dtypes import ( # noqa: F401
55
ExtensionDtype,

pandas/core/arrays/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def __iter__(self):
351351
for i in range(len(self)):
352352
yield self[i]
353353

354-
def to_numpy(self, dtype=None, copy=False, na_value=lib._no_default):
354+
def to_numpy(self, dtype=None, copy=False, na_value=lib.no_default):
355355
"""
356356
Convert to a NumPy ndarray.
357357
@@ -378,9 +378,9 @@ def to_numpy(self, dtype=None, copy=False, na_value=lib._no_default):
378378
numpy.ndarray
379379
"""
380380
result = np.asarray(self, dtype=dtype)
381-
if copy or na_value is not lib._no_default:
381+
if copy or na_value is not lib.no_default:
382382
result = result.copy()
383-
if na_value is not lib._no_default:
383+
if na_value is not lib.no_default:
384384
result[self.isna()] = na_value
385385
return result
386386

pandas/core/arrays/boolean.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def __getitem__(self, item):
317317
return type(self)(self._data[item], self._mask[item])
318318

319319
def to_numpy(
320-
self, dtype=None, copy=False, na_value: "Scalar" = lib._no_default,
320+
self, dtype=None, copy=False, na_value: "Scalar" = lib.no_default,
321321
):
322322
"""
323323
Convert to a NumPy Array.
@@ -377,7 +377,7 @@ def to_numpy(
377377
>>> a.to_numpy(dtype="bool", na_value=False)
378378
array([ True, False, False])
379379
"""
380-
if na_value is lib._no_default:
380+
if na_value is lib.no_default:
381381
na_value = libmissing.NA
382382
if dtype is None:
383383
dtype = object

pandas/core/arrays/integer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,16 +376,16 @@ def __getitem__(self, item):
376376

377377
return type(self)(self._data[item], self._mask[item])
378378

379-
def _coerce_to_ndarray(self, dtype=None, na_value=lib._no_default):
379+
def _coerce_to_ndarray(self, dtype=None, na_value=lib.no_default):
380380
"""
381381
coerce to an ndarary of object dtype
382382
"""
383383
if dtype is None:
384384
dtype = object
385385

386-
if na_value is lib._no_default and is_float_dtype(dtype):
386+
if na_value is lib.no_default and is_float_dtype(dtype):
387387
na_value = np.nan
388-
elif na_value is lib._no_default:
388+
elif na_value is lib.no_default:
389389
na_value = libmissing.NA
390390

391391
if is_integer_dtype(dtype):

pandas/core/arrays/numpy_.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,13 @@ def skew(self, axis=None, dtype=None, out=None, keepdims=False, skipna=True):
421421

422422
# ------------------------------------------------------------------------
423423
# Additional Methods
424-
def to_numpy(self, dtype=None, copy=False, na_value=lib._no_default):
424+
def to_numpy(self, dtype=None, copy=False, na_value=lib.no_default):
425425
result = np.asarray(self._ndarray, dtype=dtype)
426426

427-
if (copy or na_value is not lib._no_default) and result is self._ndarray:
427+
if (copy or na_value is not lib.no_default) and result is self._ndarray:
428428
result = result.copy()
429429

430-
if na_value is not lib._no_default:
430+
if na_value is not lib.no_default:
431431
result[self.isna()] = na_value
432432

433433
return result

pandas/core/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ def array(self) -> ExtensionArray:
768768

769769
return result
770770

771-
def to_numpy(self, dtype=None, copy=False, na_value=lib._no_default, **kwargs):
771+
def to_numpy(self, dtype=None, copy=False, na_value=lib.no_default, **kwargs):
772772
"""
773773
A NumPy ndarray representing the values in this Series or Index.
774774
@@ -874,9 +874,9 @@ def to_numpy(self, dtype=None, copy=False, na_value=lib._no_default, **kwargs):
874874

875875
result = np.asarray(self._values, dtype=dtype)
876876
# TODO(GH-24345): Avoid potential double copy
877-
if copy or na_value is not lib._no_default:
877+
if copy or na_value is not lib.no_default:
878878
result = result.copy()
879-
if na_value is not lib._no_default:
879+
if na_value is not lib.no_default:
880880
result[self.isna()] = na_value
881881
return result
882882

pandas/core/computation/eval.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Optional
99
import warnings
1010

11-
from pandas._libs.lib import _no_default
11+
from pandas._libs.lib import no_default
1212
from pandas.util._validators import validate_bool_kwarg
1313

1414
from pandas.core.computation.engines import _engines
@@ -171,7 +171,7 @@ def eval(
171171
expr,
172172
parser="pandas",
173173
engine: Optional[str] = None,
174-
truediv=_no_default,
174+
truediv=no_default,
175175
local_dict=None,
176176
global_dict=None,
177177
resolvers=(),
@@ -288,7 +288,7 @@ def eval(
288288

289289
inplace = validate_bool_kwarg(inplace, "inplace")
290290

291-
if truediv is not _no_default:
291+
if truediv is not no_default:
292292
warnings.warn(
293293
"The `truediv` parameter in pd.eval is deprecated and will be "
294294
"removed in a future version.",

pandas/core/generic.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@
106106
Name or list of names to sort by""",
107107
)
108108

109-
# sentinel value to use as kwarg in place of None when None has special meaning
110-
# and needs to be distinguished from a user explicitly passing None.
111-
sentinel = object()
112-
113109

114110
def _single_replace(self, to_replace, method, inplace, limit):
115111
"""
@@ -1086,7 +1082,7 @@ def rename(self, *args, **kwargs):
10861082
return result.__finalize__(self)
10871083

10881084
@rewrite_axis_style_signature("mapper", [("copy", True), ("inplace", False)])
1089-
def rename_axis(self, mapper=sentinel, **kwargs):
1085+
def rename_axis(self, mapper=lib.no_default, **kwargs):
10901086
"""
10911087
Set the name of the axis for the index or columns.
10921088
@@ -1211,7 +1207,7 @@ class name
12111207
monkey 2 2
12121208
"""
12131209
axes, kwargs = self._construct_axes_from_arguments(
1214-
(), kwargs, sentinel=sentinel
1210+
(), kwargs, sentinel=lib.no_default
12151211
)
12161212
copy = kwargs.pop("copy", True)
12171213
inplace = kwargs.pop("inplace", False)
@@ -1227,7 +1223,7 @@ class name
12271223

12281224
inplace = validate_bool_kwarg(inplace, "inplace")
12291225

1230-
if mapper is not sentinel:
1226+
if mapper is not lib.no_default:
12311227
# Use v0.23 behavior if a scalar or list
12321228
non_mapper = is_scalar(mapper) or (
12331229
is_list_like(mapper) and not is_dict_like(mapper)
@@ -1243,7 +1239,7 @@ class name
12431239

12441240
for axis in range(self._AXIS_LEN):
12451241
v = axes.get(self._AXIS_NAMES[axis])
1246-
if v is sentinel:
1242+
if v is lib.no_default:
12471243
continue
12481244
non_mapper = is_scalar(v) or (is_list_like(v) and not is_dict_like(v))
12491245
if non_mapper:

0 commit comments

Comments
 (0)