Skip to content

TYP: misc cleanup in core\generic.py #35963

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
Aug 29, 2020
Merged
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
16 changes: 10 additions & 6 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def _get_block_manager_axis(cls, axis: Axis) -> int:
return m - axis
return axis

def _get_axis_resolvers(self, axis: str) -> Dict[str, ABCSeries]:
def _get_axis_resolvers(self, axis: str) -> Dict[str, Union["Series", MultiIndex]]:
# index or columns
axis_index = getattr(self, axis)
d = dict()
Expand Down Expand Up @@ -417,10 +417,10 @@ def _get_axis_resolvers(self, axis: str) -> Dict[str, ABCSeries]:
d[axis] = dindex
return d

def _get_index_resolvers(self) -> Dict[str, ABCSeries]:
def _get_index_resolvers(self) -> Dict[str, Union["Series", MultiIndex]]:
from pandas.core.computation.parsing import clean_column_name

d: Dict[str, ABCSeries] = {}
d: Dict[str, Union["Series", MultiIndex]] = {}
for axis_name in self._AXIS_ORDERS:
d.update(self._get_axis_resolvers(axis_name))

Expand Down Expand Up @@ -4703,14 +4703,15 @@ def filter(
return self.reindex(**{name: [r for r in items if r in labels]})
elif like:

def f(x):
def f(x) -> bool:
assert like is not None # needed for mypy
return like in ensure_str(x)

values = labels.map(f)
return self.loc(axis=axis)[values]
elif regex:

def f(x):
def f(x) -> bool:
return matcher.search(ensure_str(x)) is not None

matcher = re.compile(regex)
Expand Down Expand Up @@ -6556,7 +6557,10 @@ def replace(
regex = True

items = list(to_replace.items())
keys, values = zip(*items) if items else ([], [])
if items:
keys, values = zip(*items)
else:
keys, values = ([], [])

are_mappings = [is_dict_like(v) for v in values]

Expand Down