Skip to content

TYP/CLN: small cleanups from flake-pyi #47850

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 4 commits into from
Jul 26, 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ repos:
language: python
additional_dependencies:
- flake8==4.0.1
- flake8-pyi==22.5.1
- flake8-pyi==22.7.0
- id: future-annotations
name: import annotations from __future__
entry: 'from __future__ import annotations'
Expand Down
2 changes: 0 additions & 2 deletions pandas/_libs/algos.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

from typing import Any

import numpy as np
Expand Down
20 changes: 9 additions & 11 deletions pandas/_libs/interval.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

from typing import (
Any,
Generic,
Expand Down Expand Up @@ -84,7 +82,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
self: Interval[_OrderableTimesT], key: _OrderableTimesT
) -> bool: ...
@overload
def __contains__(self: Interval[_OrderableScalarT], key: int | float) -> bool: ...
def __contains__(self: Interval[_OrderableScalarT], key: float) -> bool: ...
@overload
def __add__(
self: Interval[_OrderableTimesT], y: Timedelta
Expand All @@ -94,7 +92,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
self: Interval[int], y: _OrderableScalarT
) -> Interval[_OrderableScalarT]: ...
@overload
def __add__(self: Interval[float], y: int | float) -> Interval[float]: ...
def __add__(self: Interval[float], y: float) -> Interval[float]: ...
@overload
def __radd__(
self: Interval[_OrderableTimesT], y: Timedelta
Expand All @@ -104,7 +102,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
self: Interval[int], y: _OrderableScalarT
) -> Interval[_OrderableScalarT]: ...
@overload
def __radd__(self: Interval[float], y: int | float) -> Interval[float]: ...
def __radd__(self: Interval[float], y: float) -> Interval[float]: ...
@overload
def __sub__(
self: Interval[_OrderableTimesT], y: Timedelta
Expand All @@ -114,7 +112,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
self: Interval[int], y: _OrderableScalarT
) -> Interval[_OrderableScalarT]: ...
@overload
def __sub__(self: Interval[float], y: int | float) -> Interval[float]: ...
def __sub__(self: Interval[float], y: float) -> Interval[float]: ...
@overload
def __rsub__(
self: Interval[_OrderableTimesT], y: Timedelta
Expand All @@ -124,31 +122,31 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
self: Interval[int], y: _OrderableScalarT
) -> Interval[_OrderableScalarT]: ...
@overload
def __rsub__(self: Interval[float], y: int | float) -> Interval[float]: ...
def __rsub__(self: Interval[float], y: float) -> Interval[float]: ...
@overload
def __mul__(
self: Interval[int], y: _OrderableScalarT
) -> Interval[_OrderableScalarT]: ...
@overload
def __mul__(self: Interval[float], y: int | float) -> Interval[float]: ...
def __mul__(self: Interval[float], y: float) -> Interval[float]: ...
@overload
def __rmul__(
self: Interval[int], y: _OrderableScalarT
) -> Interval[_OrderableScalarT]: ...
@overload
def __rmul__(self: Interval[float], y: int | float) -> Interval[float]: ...
def __rmul__(self: Interval[float], y: float) -> Interval[float]: ...
@overload
def __truediv__(
self: Interval[int], y: _OrderableScalarT
) -> Interval[_OrderableScalarT]: ...
@overload
def __truediv__(self: Interval[float], y: int | float) -> Interval[float]: ...
def __truediv__(self: Interval[float], y: float) -> Interval[float]: ...
@overload
def __floordiv__(
self: Interval[int], y: _OrderableScalarT
) -> Interval[_OrderableScalarT]: ...
@overload
def __floordiv__(self: Interval[float], y: int | float) -> Interval[float]: ...
def __floordiv__(self: Interval[float], y: float) -> Interval[float]: ...
def overlaps(self: Interval[_OrderableT], other: Interval[_OrderableT]) -> bool: ...

def intervals_to_interval_bounds(
Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/join.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def asof_join_backward_on_X_by_Y(
left_by_values: np.ndarray, # by_t[:]
right_by_values: np.ndarray, # by_t[:]
allow_exact_matches: bool = ...,
tolerance: np.number | int | float | None = ...,
tolerance: np.number | float | None = ...,
use_hashtable: bool = ...,
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
def asof_join_forward_on_X_by_Y(
Expand All @@ -64,7 +64,7 @@ def asof_join_forward_on_X_by_Y(
left_by_values: np.ndarray, # by_t[:]
right_by_values: np.ndarray, # by_t[:]
allow_exact_matches: bool = ...,
tolerance: np.number | int | float | None = ...,
tolerance: np.number | float | None = ...,
use_hashtable: bool = ...,
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
def asof_join_nearest_on_X_by_Y(
Expand All @@ -73,6 +73,6 @@ def asof_join_nearest_on_X_by_Y(
left_by_values: np.ndarray, # by_t[:]
right_by_values: np.ndarray, # by_t[:]
allow_exact_matches: bool = ...,
tolerance: np.number | int | float | None = ...,
tolerance: np.number | float | None = ...,
use_hashtable: bool = ...,
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
2 changes: 1 addition & 1 deletion pandas/_libs/json.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def dumps(
date_unit: str = ...,
iso_dates: bool = ...,
default_handler: None
| Callable[[Any], str | int | float | bool | list | dict | None] = ...,
| Callable[[Any], str | float | bool | list | dict | None] = ...,
) -> str: ...
def loads(
s: str,
Expand Down
2 changes: 0 additions & 2 deletions pandas/_libs/tslibs/offsets.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

from datetime import (
datetime,
timedelta,
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Timedelta(timedelta):
cls: type[_S],
value=...,
unit: str = ...,
**kwargs: int | float | np.integer | np.floating,
**kwargs: float | np.integer | np.floating,
) -> _S: ...
# GH 46171
# While Timedelta can return pd.NaT, having the constructor return
Expand Down Expand Up @@ -123,7 +123,7 @@ class Timedelta(timedelta):
@overload # type: ignore[override]
def __floordiv__(self, other: timedelta) -> int: ...
@overload
def __floordiv__(self, other: int | float) -> Timedelta: ...
def __floordiv__(self, other: float) -> Timedelta: ...
@overload
def __floordiv__(
self, other: npt.NDArray[np.timedelta64]
Expand Down
8 changes: 1 addition & 7 deletions pandas/_libs/tslibs/timestamps.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ class Timestamp(datetime):
value: int # np.int64
def __new__(
cls: type[_DatetimeT],
ts_input: int
| np.integer
| float
| str
| _date
| datetime
| np.datetime64 = ...,
ts_input: np.integer | float | str | _date | datetime | np.datetime64 = ...,
freq: int | None | str | BaseOffset = ...,
tz: str | _tzinfo | None | int = ...,
unit: str | int | None = ...,
Expand Down
2 changes: 0 additions & 2 deletions pandas/_libs/writers.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import numpy as np

from pandas._typing import ArrayLike
Expand Down
8 changes: 4 additions & 4 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

# scalars

PythonScalar = Union[str, int, float, bool]
PythonScalar = Union[str, float, bool]
DatetimeLikeScalar = Union["Period", "Timestamp", "Timedelta"]
PandasScalar = Union["Period", "Timestamp", "Timedelta", "Interval"]
Scalar = Union[PythonScalar, PandasScalar, np.datetime64, np.timedelta64, datetime]
Expand All @@ -92,10 +92,10 @@
# timestamp and timedelta convertible types

TimestampConvertibleTypes = Union[
"Timestamp", datetime, np.datetime64, int, np.int64, float, str
"Timestamp", datetime, np.datetime64, np.int64, float, str
]
TimedeltaConvertibleTypes = Union[
"Timedelta", timedelta, np.timedelta64, int, np.int64, float, str
"Timedelta", timedelta, np.timedelta64, np.int64, float, str
]
Timezone = Union[str, tzinfo]

Expand Down Expand Up @@ -126,7 +126,7 @@
]

# dtypes
NpDtype = Union[str, np.dtype, type_t[Union[str, float, int, complex, bool, object]]]
NpDtype = Union[str, np.dtype, type_t[Union[str, complex, bool, object]]]
Dtype = Union["ExtensionDtype", NpDtype]
AstypeArg = Union["ExtensionDtype", "npt.DTypeLike"]
# DtypeArg specifies all allowable dtypes in a functions its dtype argument
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -2170,11 +2170,11 @@ def validate_periods(periods: None) -> None:


@overload
def validate_periods(periods: int | float) -> int:
def validate_periods(periods: float) -> int:
...


def validate_periods(periods: int | float | None) -> int | None:
def validate_periods(periods: float | None) -> int | None:
"""
If a `periods` argument is passed to the Datetime/Timedelta Array/Index
constructor, cast it to an integer.
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2563,7 +2563,7 @@ def to_stata(
compression: CompressionOptions = "infer",
storage_options: StorageOptions = None,
*,
value_labels: dict[Hashable, dict[float | int, str]] | None = None,
value_labels: dict[Hashable, dict[float, str]] | None = None,
) -> None:
"""
Export DataFrame object to Stata dta format.
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ def _get_counts_nanvar(
axis: int | None,
ddof: int,
dtype: np.dtype = np.dtype(np.float64),
) -> tuple[int | float | np.ndarray, int | float | np.ndarray]:
) -> tuple[float | np.ndarray, float | np.ndarray]:
"""
Get the count of non-null values along an axis, accounting
for degrees of freedom.
Expand Down Expand Up @@ -1414,7 +1414,7 @@ def _get_counts(
mask: npt.NDArray[np.bool_] | None,
axis: int | None,
dtype: np.dtype = np.dtype(np.float64),
) -> int | float | np.ndarray:
) -> float | np.ndarray:
"""
Get the count of non-null values along an axis

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def get_empty_frame(data) -> DataFrame:

if sparse:

fill_value: bool | float | int
fill_value: bool | float
if is_integer_dtype(dtype):
fill_value = 0
elif dtype == np.dtype(bool):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
# types used in annotations

ArrayConvertible = Union[List, Tuple, AnyArrayLike]
Scalar = Union[int, float, str]
Scalar = Union[float, str]
DatetimeScalar = Union[Scalar, datetime]

DatetimeScalarOrArrayConvertible = Union[DatetimeScalar, ArrayConvertible]
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/tools/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

@overload
def to_timedelta(
arg: str | int | float | timedelta,
arg: str | float | timedelta,
unit: UnitChoices | None = ...,
errors: DateTimeErrorChoices = ...,
) -> Timedelta:
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def build_number_format(self, props: Mapping[str, str]) -> dict[str, str | None]

def build_font(
self, props: Mapping[str, str]
) -> dict[str, bool | int | float | str | None]:
) -> dict[str, bool | float | str | None]:
font_names = self._get_font_names(props)
decoration = self._get_decoration(props)
return {
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ def __init__(self, *args, **kwargs) -> None:
def _value_formatter(
self,
float_format: FloatFormatType | None = None,
threshold: float | int | None = None,
threshold: float | None = None,
) -> Callable:
"""Returns a function to be applied on each value to format it"""
# the float_format parameter supersedes self.float_format
Expand Down Expand Up @@ -2047,7 +2047,7 @@ def __init__(
self.accuracy = accuracy
self.use_eng_prefix = use_eng_prefix

def __call__(self, num: int | float) -> str:
def __call__(self, num: float) -> str:
"""
Formats a number in engineering notation, appending a letter
representing the power of 1000 of the original number. Some examples:
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def _put_str(s: str | Dtype, space: int) -> str:
return str(s)[:space].ljust(space)


def _sizeof_fmt(num: int | float, size_qualifier: str) -> str:
def _sizeof_fmt(num: float, size_qualifier: str) -> str:
"""
Return size in human readable format.
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -3213,7 +3213,7 @@ def bar(
cmap: Any | None = None,
width: float = 100,
height: float = 100,
align: str | float | int | Callable = "mid",
align: str | float | Callable = "mid",
vmin: float | None = None,
vmax: float | None = None,
props: str = "width: 10em;",
Expand Down Expand Up @@ -4039,7 +4039,7 @@ def _highlight_value(data: DataFrame | Series, op: str, props: str) -> np.ndarra

def _bar(
data: NDFrame,
align: str | float | int | Callable,
align: str | float | Callable,
colors: str | list | tuple,
cmap: Any,
width: float,
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/formats/style_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

BaseFormatter = Union[str, Callable]
ExtFormatter = Union[BaseFormatter, Dict[Any, Optional[BaseFormatter]]]
CSSPair = Tuple[str, Union[str, int, float]]
CSSPair = Tuple[str, Union[str, float]]
CSSList = List[CSSPair]
CSSProperties = Union[str, CSSList]

Expand Down Expand Up @@ -2055,7 +2055,7 @@ def _parse_latex_header_span(
return display_val


def _parse_latex_options_strip(value: str | int | float, arg: str) -> str:
def _parse_latex_options_strip(value: str | float, arg: str) -> str:
"""
Strip a css_value which may have latex wrapping arguments, css comment identifiers,
and whitespaces, to a valid string for latex options parsing.
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/parsers/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def validate_integer(name, val: None, min_val=...) -> None:


@overload
def validate_integer(name, val: int | float, min_val=...) -> int:
def validate_integer(name, val: float, min_val=...) -> int:
...


Expand Down Expand Up @@ -1910,7 +1910,7 @@ def _floatify_na_values(na_values):

def _stringify_na_values(na_values):
"""return a stringified and numeric for these values"""
result: list[int | str | float] = []
result: list[str | float] = []
for x in na_values:
result.append(str(x))
result.append(x)
Expand Down
Loading