Skip to content

Commit a3ab7a3

Browse files
authored
CLN: use lib.no_default instead of lib.NoDefault in .pivot (#53877)
* CLN typo lib.NoDefault -> lib.no_default * also typo in tests
1 parent 12cb26a commit a3ab7a3

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

pandas/core/frame.py

+14-16
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@
4747
properties,
4848
)
4949
from pandas._libs.hashtable import duplicated
50-
from pandas._libs.lib import (
51-
NoDefault,
52-
is_range_indexer,
53-
no_default,
54-
)
50+
from pandas._libs.lib import is_range_indexer
5551
from pandas.compat import PYPY
5652
from pandas.compat._optional import import_optional_dependency
5753
from pandas.compat.numpy import (
@@ -6123,8 +6119,8 @@ def dropna(
61236119
self,
61246120
*,
61256121
axis: Axis = ...,
6126-
how: AnyAll | NoDefault = ...,
6127-
thresh: int | NoDefault = ...,
6122+
how: AnyAll | lib.NoDefault = ...,
6123+
thresh: int | lib.NoDefault = ...,
61286124
subset: IndexLabel = ...,
61296125
inplace: Literal[False] = ...,
61306126
ignore_index: bool = ...,
@@ -6136,8 +6132,8 @@ def dropna(
61366132
self,
61376133
*,
61386134
axis: Axis = ...,
6139-
how: AnyAll | NoDefault = ...,
6140-
thresh: int | NoDefault = ...,
6135+
how: AnyAll | lib.NoDefault = ...,
6136+
thresh: int | lib.NoDefault = ...,
61416137
subset: IndexLabel = ...,
61426138
inplace: Literal[True],
61436139
ignore_index: bool = ...,
@@ -6148,8 +6144,8 @@ def dropna(
61486144
self,
61496145
*,
61506146
axis: Axis = 0,
6151-
how: AnyAll | NoDefault = no_default,
6152-
thresh: int | NoDefault = no_default,
6147+
how: AnyAll | lib.NoDefault = lib.no_default,
6148+
thresh: int | lib.NoDefault = lib.no_default,
61536149
subset: IndexLabel = None,
61546150
inplace: bool = False,
61556151
ignore_index: bool = False,
@@ -6252,12 +6248,12 @@ def dropna(
62526248
1 Batman Batmobile 1940-04-25
62536249
2 Catwoman Bullwhip NaT
62546250
"""
6255-
if (how is not no_default) and (thresh is not no_default):
6251+
if (how is not lib.no_default) and (thresh is not lib.no_default):
62566252
raise TypeError(
62576253
"You cannot set both the how and thresh arguments at the same time."
62586254
)
62596255

6260-
if how is no_default:
6256+
if how is lib.no_default:
62616257
how = "any"
62626258

62636259
inplace = validate_bool_kwarg(inplace, "inplace")
@@ -6280,7 +6276,7 @@ def dropna(
62806276
raise KeyError(np.array(subset)[check].tolist())
62816277
agg_obj = self.take(indices, axis=agg_axis)
62826278

6283-
if thresh is not no_default:
6279+
if thresh is not lib.no_default:
62846280
count = agg_obj.count(axis=agg_axis)
62856281
mask = count >= thresh
62866282
elif how == "any":
@@ -8650,7 +8646,7 @@ def update(
86508646
def groupby(
86518647
self,
86528648
by=None,
8653-
axis: Axis | lib.NoDefault = no_default,
8649+
axis: Axis | lib.NoDefault = lib.no_default,
86548650
level: IndexLabel | None = None,
86558651
as_index: bool = True,
86568652
sort: bool = True,
@@ -8833,7 +8829,9 @@ def groupby(
88338829

88348830
@Substitution("")
88358831
@Appender(_shared_docs["pivot"])
8836-
def pivot(self, *, columns, index=lib.NoDefault, values=lib.NoDefault) -> DataFrame:
8832+
def pivot(
8833+
self, *, columns, index=lib.no_default, values=lib.no_default
8834+
) -> DataFrame:
88378835
from pandas.core.reshape.pivot import pivot
88388836

88398837
return pivot(self, index=index, columns=columns, values=values)

pandas/core/reshape/pivot.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ def pivot(
511511
data: DataFrame,
512512
*,
513513
columns: IndexLabel,
514-
index: IndexLabel | lib.NoDefault = lib.NoDefault,
515-
values: IndexLabel | lib.NoDefault = lib.NoDefault,
514+
index: IndexLabel | lib.NoDefault = lib.no_default,
515+
values: IndexLabel | lib.NoDefault = lib.no_default,
516516
) -> DataFrame:
517517
columns_listlike = com.convert_to_list_like(columns)
518518

@@ -522,24 +522,24 @@ def pivot(
522522
data = data.copy(deep=False)
523523
data.index = data.index.copy()
524524
data.index.names = [
525-
name if name is not None else lib.NoDefault for name in data.index.names
525+
name if name is not None else lib.no_default for name in data.index.names
526526
]
527527

528528
indexed: DataFrame | Series
529-
if values is lib.NoDefault:
530-
if index is not lib.NoDefault:
529+
if values is lib.no_default:
530+
if index is not lib.no_default:
531531
cols = com.convert_to_list_like(index)
532532
else:
533533
cols = []
534534

535-
append = index is lib.NoDefault
535+
append = index is lib.no_default
536536
# error: Unsupported operand types for + ("List[Any]" and "ExtensionArray")
537537
# error: Unsupported left operand type for + ("ExtensionArray")
538538
indexed = data.set_index(
539539
cols + columns_listlike, append=append # type: ignore[operator]
540540
)
541541
else:
542-
if index is lib.NoDefault:
542+
if index is lib.no_default:
543543
if isinstance(data.index, MultiIndex):
544544
# GH 23955
545545
index_list = [
@@ -569,7 +569,7 @@ def pivot(
569569
# "Hashable"
570570
result = indexed.unstack(columns_listlike) # type: ignore[arg-type]
571571
result.index.names = [
572-
name if name is not lib.NoDefault else None for name in result.index.names
572+
name if name is not lib.no_default else None for name in result.index.names
573573
]
574574

575575
return result

pandas/tests/reshape/test_pivot_multilevel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
(
3636
["lev4"],
3737
"lev3",
38-
lib.NoDefault,
38+
lib.no_default,
3939
[
4040
[1.0, np.nan, 1.0, np.nan, 0.0, np.nan],
4141
[np.nan, 1.0, np.nan, 1.0, np.nan, 1.0],
@@ -72,7 +72,7 @@
7272
(
7373
["lev1", "lev2"],
7474
"lev3",
75-
lib.NoDefault,
75+
lib.no_default,
7676
[[1, 2, 0, 1], [3, 4, 2, 3], [5, 6, 4, 5], [7, 8, 6, 7]],
7777
MultiIndex.from_tuples(
7878
[("lev4", 1), ("lev4", 2), ("values", 1), ("values", 2)],

0 commit comments

Comments
 (0)