Skip to content

TYP: resolve ignored mypy errors in core/describe.py #46928

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
May 6, 2022
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
21 changes: 8 additions & 13 deletions pandas/core/describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import numpy as np

from pandas._libs.tslibs import Timestamp
from pandas._typing import NDFrameT
from pandas._typing import (
NDFrameT,
npt,
)
from pandas.util._exceptions import find_stack_level
from pandas.util._validators import validate_percentile

Expand Down Expand Up @@ -186,11 +189,9 @@ def _select_data(self):
"""Select columns to be described."""
if (self.include is None) and (self.exclude is None):
# when some numerics are found, keep only numerics
default_include = [np.number]
default_include: list[npt.DTypeLike] = [np.number]
if self.datetime_is_numeric:
# error: Argument 1 to "append" of "list" has incompatible type "str";
# expected "Type[number[Any]]"
default_include.append("datetime") # type: ignore[arg-type]
default_include.append("datetime")
data = self.obj.select_dtypes(include=default_include)
if len(data.columns) == 0:
data = self.obj
Expand Down Expand Up @@ -230,10 +231,7 @@ def describe_numeric_1d(series: Series, percentiles: Sequence[float]) -> Series:
"""
from pandas import Series

# error: Argument 1 to "format_percentiles" has incompatible type "Sequence[float]";
# expected "Union[ndarray, List[Union[int, float]], List[float], List[Union[str,
# float]]]"
formatted_percentiles = format_percentiles(percentiles) # type: ignore[arg-type]
formatted_percentiles = format_percentiles(percentiles)

stat_index = ["count", "mean", "std", "min"] + formatted_percentiles + ["max"]
d = (
Expand Down Expand Up @@ -337,10 +335,7 @@ def describe_timestamp_1d(data: Series, percentiles: Sequence[float]) -> Series:
# GH-30164
from pandas import Series

# error: Argument 1 to "format_percentiles" has incompatible type "Sequence[float]";
# expected "Union[ndarray, List[Union[int, float]], List[float], List[Union[str,
# float]]]"
formatted_percentiles = format_percentiles(percentiles) # type: ignore[arg-type]
formatted_percentiles = format_percentiles(percentiles)

stat_index = ["count", "mean", "min"] + formatted_percentiles + ["max"]
d = (
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ def _format_strings(self) -> list[str]:


def format_percentiles(
percentiles: (np.ndarray | list[int | float] | list[float] | list[str | float]),
percentiles: (np.ndarray | Sequence[float]),
Copy link
Member

Choose a reason for hiding this comment

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

Was there a reason why the function was supposed to accept strings? @jreback I don't think it supports str as one of the first lines isnp.isclose(percentiles.astype(int), percentiles) which should fail for str (didn't try it)?

Copy link
Contributor

Choose a reason for hiding this comment

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

don't remember. happy to eliminate it (assume we don't have tests / usage for this)

) -> list[str]:
"""
Outputs rounded and formatted percentiles.
Expand Down