Skip to content

TYP: fix a few errors found by pandas-stub #47562

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 5 commits into from
Jul 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ def assert_series_equal(
check_dtype: bool | Literal["equiv"] = True,
check_index_type="equiv",
check_series_type=True,
check_less_precise=no_default,
check_less_precise: bool | int | NoDefault = no_default,
check_names=True,
check_exact=False,
check_datetimelike_compat=False,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ def _rename(
return result.__finalize__(self, method="rename")

@rewrite_axis_style_signature("mapper", [("copy", True), ("inplace", False)])
def rename_axis(self, mapper=lib.no_default, **kwargs):
def rename_axis(self, mapper: IndexLabel = lib.no_default, **kwargs):
"""
Set the name of the axis for the index or columns.

Expand Down
7 changes: 6 additions & 1 deletion pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -4050,7 +4050,12 @@ def _reindex_output(
# "ndarray[Any, dtype[floating[_64Bit]]]"; expected "Index"
levels_list.append(qs) # type: ignore[arg-type]
names = names + [None]
index, _ = MultiIndex.from_product(levels_list, names=names).sortlevel()
# error: Argument "names" to "from_product" of "MultiIndex" has
# incompatible type "List[Hashable]"; expected "Union[Sequence[
# Optional[str]], Literal[_NoDefault.no_default]]"
index, _ = MultiIndex.from_product(
levels_list, names=names # type: ignore[arg-type]
).sortlevel()

if self.as_index:
# Always holds for SeriesGroupBy unless GH#36507 is implemented
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,10 @@ def from_tuples(

@classmethod
def from_product(
cls, iterables, sortorder=None, names=lib.no_default
cls,
iterables: Sequence[Iterable[Hashable]],
sortorder: int | None = None,
names: Sequence[str | None] | lib.NoDefault = lib.no_default,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think names: Sequence[Level | None] | lib.NoDefault or similar as the docstring is under-specifying what can be accepted here (more than just strings)

In [1]:         >>> numbers = [0, 1, 2]
   ...:         >>> colors = ['green', 'purple']
   ...:         >>> pd.MultiIndex.from_product([numbers, colors],
   ...:         ...                            names=[55, 60])
Out[1]:
MultiIndex([(0,  'green'),
            (0, 'purple'),
            (1,  'green'),
            (1, 'purple'),
            (2,  'green'),
            (2, 'purple')],
           names=[55, 60])

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing all of the typing PRs!

) -> MultiIndex:
"""
Make a MultiIndex from the cartesian product of multiple iterables.
Expand Down
4 changes: 3 additions & 1 deletion pandas/plotting/_matplotlib/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ def reconstruct_data_with_by(

data_list = []
for key, group in grouped:
columns = MultiIndex.from_product([[key], cols])
# error: List item 1 has incompatible type "Union[Hashable,
# Sequence[Hashable]]"; expected "Iterable[Hashable]"
columns = MultiIndex.from_product([[key], cols]) # type: ignore[list-item]
sub_group = group[cols]
sub_group.columns = columns
data_list.append(sub_group)
Expand Down