Skip to content
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

CLN: use lib.no_default instead of lib.NoDefault in .pivot #53877

Merged
merged 4 commits into from
Jun 27, 2023
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
30 changes: 14 additions & 16 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@
properties,
)
from pandas._libs.hashtable import duplicated
from pandas._libs.lib import (
NoDefault,
is_range_indexer,
no_default,
)
from pandas._libs.lib import is_range_indexer
from pandas.compat import PYPY
from pandas.compat._optional import import_optional_dependency
from pandas.compat.numpy import (
Expand Down Expand Up @@ -6118,8 +6114,8 @@ def dropna(
self,
*,
axis: Axis = ...,
how: AnyAll | NoDefault = ...,
thresh: int | NoDefault = ...,
how: AnyAll | lib.NoDefault = ...,
thresh: int | lib.NoDefault = ...,
subset: IndexLabel = ...,
inplace: Literal[False] = ...,
ignore_index: bool = ...,
Expand All @@ -6131,8 +6127,8 @@ def dropna(
self,
*,
axis: Axis = ...,
how: AnyAll | NoDefault = ...,
thresh: int | NoDefault = ...,
how: AnyAll | lib.NoDefault = ...,
thresh: int | lib.NoDefault = ...,
subset: IndexLabel = ...,
inplace: Literal[True],
ignore_index: bool = ...,
Expand All @@ -6143,8 +6139,8 @@ def dropna(
self,
*,
axis: Axis = 0,
how: AnyAll | NoDefault = no_default,
thresh: int | NoDefault = no_default,
how: AnyAll | lib.NoDefault = lib.no_default,
thresh: int | lib.NoDefault = lib.no_default,
subset: IndexLabel = None,
inplace: bool = False,
ignore_index: bool = False,
Expand Down Expand Up @@ -6247,12 +6243,12 @@ def dropna(
1 Batman Batmobile 1940-04-25
2 Catwoman Bullwhip NaT
"""
if (how is not no_default) and (thresh is not no_default):
if (how is not lib.no_default) and (thresh is not lib.no_default):
raise TypeError(
"You cannot set both the how and thresh arguments at the same time."
)

if how is no_default:
if how is lib.no_default:
how = "any"

inplace = validate_bool_kwarg(inplace, "inplace")
Expand All @@ -6275,7 +6271,7 @@ def dropna(
raise KeyError(np.array(subset)[check].tolist())
agg_obj = self.take(indices, axis=agg_axis)

if thresh is not no_default:
if thresh is not lib.no_default:
count = agg_obj.count(axis=agg_axis)
mask = count >= thresh
elif how == "any":
Expand Down Expand Up @@ -8645,7 +8641,7 @@ def update(
def groupby(
self,
by=None,
axis: Axis | lib.NoDefault = no_default,
axis: Axis | lib.NoDefault = lib.no_default,
level: IndexLabel | None = None,
as_index: bool = True,
sort: bool = True,
Expand Down Expand Up @@ -8828,7 +8824,9 @@ def groupby(

@Substitution("")
@Appender(_shared_docs["pivot"])
def pivot(self, *, columns, index=lib.NoDefault, values=lib.NoDefault) -> DataFrame:
def pivot(
self, *, columns, index=lib.no_default, values=lib.no_default
) -> DataFrame:
from pandas.core.reshape.pivot import pivot

return pivot(self, index=index, columns=columns, values=values)
Expand Down
16 changes: 8 additions & 8 deletions pandas/core/reshape/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ def pivot(
data: DataFrame,
*,
columns: IndexLabel,
index: IndexLabel | lib.NoDefault = lib.NoDefault,
values: IndexLabel | lib.NoDefault = lib.NoDefault,
index: IndexLabel | lib.NoDefault = lib.no_default,
values: IndexLabel | lib.NoDefault = lib.no_default,
) -> DataFrame:
columns_listlike = com.convert_to_list_like(columns)

Expand All @@ -522,24 +522,24 @@ def pivot(
data = data.copy(deep=False)
data.index = data.index.copy()
data.index.names = [
name if name is not None else lib.NoDefault for name in data.index.names
name if name is not None else lib.no_default for name in data.index.names
]

indexed: DataFrame | Series
if values is lib.NoDefault:
if index is not lib.NoDefault:
if values is lib.no_default:
if index is not lib.no_default:
cols = com.convert_to_list_like(index)
else:
cols = []

append = index is lib.NoDefault
append = index is lib.no_default
# error: Unsupported operand types for + ("List[Any]" and "ExtensionArray")
# error: Unsupported left operand type for + ("ExtensionArray")
indexed = data.set_index(
cols + columns_listlike, append=append # type: ignore[operator]
)
else:
if index is lib.NoDefault:
if index is lib.no_default:
if isinstance(data.index, MultiIndex):
# GH 23955
index_list = [
Expand Down Expand Up @@ -569,7 +569,7 @@ def pivot(
# "Hashable"
result = indexed.unstack(columns_listlike) # type: ignore[arg-type]
result.index.names = [
name if name is not lib.NoDefault else None for name in result.index.names
name if name is not lib.no_default else None for name in result.index.names
]

return result
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/reshape/test_pivot_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
(
["lev4"],
"lev3",
lib.NoDefault,
lib.no_default,
[
[1.0, np.nan, 1.0, np.nan, 0.0, np.nan],
[np.nan, 1.0, np.nan, 1.0, np.nan, 1.0],
Expand Down Expand Up @@ -72,7 +72,7 @@
(
["lev1", "lev2"],
"lev3",
lib.NoDefault,
lib.no_default,
[[1, 2, 0, 1], [3, 4, 2, 3], [5, 6, 4, 5], [7, 8, 6, 7]],
MultiIndex.from_tuples(
[("lev4", 1), ("lev4", 2), ("values", 1), ("values", 2)],
Expand Down