diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index b8d79d0835fb8..4b423175172d2 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -2440,6 +2440,9 @@ class NoDefault(Enum): # 2) because mypy does not understand singletons no_default = "NO_DEFAULT" + def __repr__(self) -> str: + return "" + # Note: no_default is exported to the public API in pandas.api.extensions no_default = NoDefault.no_default # Sentinel indicating the default value. diff --git a/pandas/core/base.py b/pandas/core/base.py index 18fc76fe79a5a..b0c2af89ad0c7 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -1164,7 +1164,7 @@ def is_monotonic_decreasing(self) -> bool: return Index(self).is_monotonic_decreasing - def memory_usage(self, deep=False): + def _memory_usage(self, deep: bool = False) -> int: """ Memory usage of the values. diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 29c2f7cfcf00d..c3f3476618bf0 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -12,7 +12,6 @@ FrozenSet, Hashable, List, - NewType, Optional, Sequence, Set, @@ -195,9 +194,6 @@ _o_dtype = np.dtype("object") -_Identity = NewType("_Identity", object) - - def disallow_kwargs(kwargs: Dict[str, Any]): if kwargs: raise TypeError(f"Unexpected keyword arguments {repr(set(kwargs))}") @@ -4405,9 +4401,9 @@ def _get_engine_target(self) -> np.ndarray: # ndarray]", expected "ndarray") return self._values # type: ignore[return-value] - @doc(IndexOpsMixin.memory_usage) + @doc(IndexOpsMixin._memory_usage) def memory_usage(self, deep: bool = False) -> int: - result = super().memory_usage(deep=deep) + result = self._memory_usage(deep=deep) # include our engine hashtable result += self._engine.sizeof(deep=deep) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 944844dfbbb5b..e605486e0044e 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -207,6 +207,7 @@ def is_bool(self) -> bool: def external_values(self): return external_values(self.values) + @final def internal_values(self): """ The array that Series._values returns (internal values). @@ -593,8 +594,6 @@ def astype(self, dtype, copy: bool = False, errors: str = "raise"): Block """ values = self.values - if values.dtype.kind in ["m", "M"]: - values = self.array_values new_values = astype_array_safe(values, dtype, copy=copy, errors=errors) @@ -1763,10 +1762,6 @@ def is_view(self) -> bool: # check the ndarray values of the DatetimeIndex values return self.values._ndarray.base is not None - def internal_values(self): - # Override to return DatetimeArray and TimedeltaArray - return self.values - def get_values(self, dtype: Optional[DtypeObj] = None) -> np.ndarray: """ return object dtype as boxed values, such as Timestamps/Timedelta @@ -1878,7 +1873,6 @@ class DatetimeTZBlock(ExtensionBlock, DatetimeLikeBlockMixin): is_extension = True is_numeric = False - internal_values = Block.internal_values diff = DatetimeBlock.diff where = DatetimeBlock.where putmask = DatetimeLikeBlockMixin.putmask diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index de0a5687aeb8b..3c8d942554575 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -1085,17 +1085,11 @@ def value_getitem(placement): else: if value.ndim == 2: value = value.T - - if value.ndim == self.ndim - 1: - value = ensure_block_shape(value, ndim=2) - - def value_getitem(placement): - return value - else: + value = ensure_block_shape(value, ndim=2) - def value_getitem(placement): - return value[placement.indexer] + def value_getitem(placement): + return value[placement.indexer] if value.shape[1:] != self.shape[1:]: raise AssertionError( diff --git a/pandas/core/series.py b/pandas/core/series.py index 27ebf7f228bc0..4ade9992e9e3e 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4609,7 +4609,7 @@ def shift(self, periods=1, freq=None, axis=0, fill_value=None) -> Series: periods=periods, freq=freq, axis=axis, fill_value=fill_value ) - def memory_usage(self, index=True, deep=False): + def memory_usage(self, index: bool = True, deep: bool = False) -> int: """ Return the memory usage of the Series. @@ -4658,7 +4658,7 @@ def memory_usage(self, index=True, deep=False): >>> s.memory_usage(deep=True) 244 """ - v = super().memory_usage(deep=deep) + v = self._memory_usage(deep=deep) if index: v += self.index.memory_usage(deep=deep) return v