Skip to content

Commit ba72b59

Browse files
authored
CLN: avoid internals, some misc cleanups (#33083)
1 parent e894809 commit ba72b59

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

pandas/core/groupby/grouper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,8 @@ def get_grouper(
561561
# if the actual grouper should be obj[key]
562562
def is_in_axis(key) -> bool:
563563
if not _is_label_like(key):
564-
items = obj._data.items
564+
# items -> .columns for DataFrame, .index for Series
565+
items = obj.axes[-1]
565566
try:
566567
items.get_loc(key)
567568
except (KeyError, TypeError, InvalidIndexError):

pandas/core/indexes/period.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index):
149149
_infer_as_myclass = True
150150

151151
_data: PeriodArray
152+
freq: DateOffset
152153

153154
_engine_type = libindex.PeriodEngine
154155
_supports_partial_string_indexing = True

pandas/core/indexing.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Hashable, List, Tuple, Union
1+
from typing import TYPE_CHECKING, Hashable, List, Tuple, Union
22

33
import numpy as np
44

@@ -29,6 +29,9 @@
2929
)
3030
from pandas.core.indexes.api import Index, InvalidIndexError
3131

32+
if TYPE_CHECKING:
33+
from pandas import DataFrame # noqa:F401
34+
3235
# "null slice"
3336
_NS = slice(None, None)
3437

@@ -2108,7 +2111,7 @@ def _tuplify(ndim: int, loc: Hashable) -> Tuple[Union[Hashable, slice], ...]:
21082111
return tuple(_tup)
21092112

21102113

2111-
def convert_to_index_sliceable(obj, key):
2114+
def convert_to_index_sliceable(obj: "DataFrame", key):
21122115
"""
21132116
If we are index sliceable, then return my slicer, otherwise return None.
21142117
"""
@@ -2119,7 +2122,7 @@ def convert_to_index_sliceable(obj, key):
21192122
elif isinstance(key, str):
21202123

21212124
# we are an actual column
2122-
if key in obj._data.items:
2125+
if key in obj.columns:
21232126
return None
21242127

21252128
# We might have a datetimelike string that we can translate to a

pandas/core/series.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
sanitize_array,
7575
)
7676
from pandas.core.generic import NDFrame
77-
from pandas.core.indexers import maybe_convert_indices, unpack_1tuple
77+
from pandas.core.indexers import unpack_1tuple
7878
from pandas.core.indexes.accessors import CombinedDatetimelikeProperties
7979
from pandas.core.indexes.api import (
8080
Float64Index,
@@ -435,7 +435,8 @@ def dtypes(self) -> DtypeObj:
435435
"""
436436
Return the dtype object of the underlying data.
437437
"""
438-
return self._data.dtype
438+
# DataFrame compatibility
439+
return self.dtype
439440

440441
@property
441442
def name(self) -> Label:
@@ -828,15 +829,7 @@ def take(self, indices, axis=0, is_copy=None, **kwargs) -> "Series":
828829

829830
indices = ensure_platform_int(indices)
830831
new_index = self.index.take(indices)
831-
832-
if is_categorical_dtype(self):
833-
# https://github.com/pandas-dev/pandas/issues/20664
834-
# TODO: remove when the default Categorical.take behavior changes
835-
indices = maybe_convert_indices(indices, len(self._get_axis(axis)))
836-
kwargs = {"allow_fill": False}
837-
else:
838-
kwargs = {}
839-
new_values = self._values.take(indices, **kwargs)
832+
new_values = self._values.take(indices)
840833

841834
return self._constructor(
842835
new_values, index=new_index, fastpath=True

pandas/io/formats/info.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ def _sizeof_fmt(num, size_qualifier):
265265
else:
266266
_verbose_repr()
267267

268-
counts = data._data.get_dtype_counts()
268+
# groupby dtype.name to collect e.g. Categorical columns
269+
counts = data.dtypes.value_counts().groupby(lambda x: x.name).sum()
269270
dtypes = [f"{k[0]}({k[1]:d})" for k in sorted(counts.items())]
270271
lines.append(f"dtypes: {', '.join(dtypes)}")
271272

0 commit comments

Comments
 (0)