diff --git a/pandas/core/frame.py b/pandas/core/frame.py index c7e8f74ff7849..e877680b3bb8d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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 ( @@ -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 = ..., @@ -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 = ..., @@ -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, @@ -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") @@ -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": @@ -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, @@ -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) diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index a030182e774fb..07985a2744069 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -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) @@ -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 = [ @@ -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 diff --git a/pandas/tests/reshape/test_pivot_multilevel.py b/pandas/tests/reshape/test_pivot_multilevel.py index c6931a1961702..08ef29440825f 100644 --- a/pandas/tests/reshape/test_pivot_multilevel.py +++ b/pandas/tests/reshape/test_pivot_multilevel.py @@ -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], @@ -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)],