Skip to content

CLN: avoid internals, some misc cleanups #33083

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 1 commit into from
Mar 29, 2020
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: 2 additions & 1 deletion pandas/core/groupby/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,8 @@ def get_grouper(
# if the actual grouper should be obj[key]
def is_in_axis(key) -> bool:
if not _is_label_like(key):
items = obj._data.items
# items -> .columns for DataFrame, .index for Series
items = obj.axes[-1]
try:
items.get_loc(key)
except (KeyError, TypeError, InvalidIndexError):
Expand Down
1 change: 1 addition & 0 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index):
_infer_as_myclass = True

_data: PeriodArray
freq: DateOffset

_engine_type = libindex.PeriodEngine
_supports_partial_string_indexing = True
Expand Down
9 changes: 6 additions & 3 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Hashable, List, Tuple, Union
from typing import TYPE_CHECKING, Hashable, List, Tuple, Union

import numpy as np

Expand Down Expand Up @@ -29,6 +29,9 @@
)
from pandas.core.indexes.api import Index, InvalidIndexError

if TYPE_CHECKING:
from pandas import DataFrame # noqa:F401

# "null slice"
_NS = slice(None, None)

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


def convert_to_index_sliceable(obj, key):
def convert_to_index_sliceable(obj: "DataFrame", key):
"""
If we are index sliceable, then return my slicer, otherwise return None.
"""
Expand All @@ -2119,7 +2122,7 @@ def convert_to_index_sliceable(obj, key):
elif isinstance(key, str):

# we are an actual column
if key in obj._data.items:
if key in obj.columns:
return None

# We might have a datetimelike string that we can translate to a
Expand Down
15 changes: 4 additions & 11 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
sanitize_array,
)
from pandas.core.generic import NDFrame
from pandas.core.indexers import maybe_convert_indices, unpack_1tuple
from pandas.core.indexers import unpack_1tuple
from pandas.core.indexes.accessors import CombinedDatetimelikeProperties
from pandas.core.indexes.api import (
Float64Index,
Expand Down Expand Up @@ -435,7 +435,8 @@ def dtypes(self) -> DtypeObj:
"""
Return the dtype object of the underlying data.
"""
return self._data.dtype
# DataFrame compatibility
return self.dtype

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

indices = ensure_platform_int(indices)
new_index = self.index.take(indices)

if is_categorical_dtype(self):
# https://github.com/pandas-dev/pandas/issues/20664
# TODO: remove when the default Categorical.take behavior changes
indices = maybe_convert_indices(indices, len(self._get_axis(axis)))
kwargs = {"allow_fill": False}
else:
kwargs = {}
new_values = self._values.take(indices, **kwargs)
new_values = self._values.take(indices)

return self._constructor(
new_values, index=new_index, fastpath=True
Expand Down
3 changes: 2 additions & 1 deletion pandas/io/formats/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ def _sizeof_fmt(num, size_qualifier):
else:
_verbose_repr()

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

Expand Down