Skip to content

CLN: follow-up cleanups #40715

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

Merged
merged 3 commits into from
Apr 2, 2021
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
3 changes: 3 additions & 0 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2440,6 +2440,9 @@ class NoDefault(Enum):
# 2) because mypy does not understand singletons
no_default = "NO_DEFAULT"

def __repr__(self) -> str:
return "<no_default>"


# Note: no_default is exported to the public API in pandas.api.extensions
no_default = NoDefault.no_default # Sentinel indicating the default value.
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
8 changes: 2 additions & 6 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
FrozenSet,
Hashable,
List,
NewType,
Optional,
Sequence,
Set,
Expand Down Expand Up @@ -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))}")
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down