Skip to content

Commit e12b318

Browse files
authored
TYP/CLN: small cleanups from flake-pyi (#47850)
* TYP/CLN: small cleanups from flake-pyi * black * manual changes in py files * some more cases
1 parent 6b7578b commit e12b318

23 files changed

+52
-66
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ repos:
230230
language: python
231231
additional_dependencies:
232232
- flake8==4.0.1
233-
- flake8-pyi==22.5.1
233+
- flake8-pyi==22.7.0
234234
- id: future-annotations
235235
name: import annotations from __future__
236236
entry: 'from __future__ import annotations'

pandas/_libs/algos.pyi

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
from typing import Any
42

53
import numpy as np

pandas/_libs/interval.pyi

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
from typing import (
42
Any,
53
Generic,
@@ -84,7 +82,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
8482
self: Interval[_OrderableTimesT], key: _OrderableTimesT
8583
) -> bool: ...
8684
@overload
87-
def __contains__(self: Interval[_OrderableScalarT], key: int | float) -> bool: ...
85+
def __contains__(self: Interval[_OrderableScalarT], key: float) -> bool: ...
8886
@overload
8987
def __add__(
9088
self: Interval[_OrderableTimesT], y: Timedelta
@@ -94,7 +92,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
9492
self: Interval[int], y: _OrderableScalarT
9593
) -> Interval[_OrderableScalarT]: ...
9694
@overload
97-
def __add__(self: Interval[float], y: int | float) -> Interval[float]: ...
95+
def __add__(self: Interval[float], y: float) -> Interval[float]: ...
9896
@overload
9997
def __radd__(
10098
self: Interval[_OrderableTimesT], y: Timedelta
@@ -104,7 +102,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
104102
self: Interval[int], y: _OrderableScalarT
105103
) -> Interval[_OrderableScalarT]: ...
106104
@overload
107-
def __radd__(self: Interval[float], y: int | float) -> Interval[float]: ...
105+
def __radd__(self: Interval[float], y: float) -> Interval[float]: ...
108106
@overload
109107
def __sub__(
110108
self: Interval[_OrderableTimesT], y: Timedelta
@@ -114,7 +112,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
114112
self: Interval[int], y: _OrderableScalarT
115113
) -> Interval[_OrderableScalarT]: ...
116114
@overload
117-
def __sub__(self: Interval[float], y: int | float) -> Interval[float]: ...
115+
def __sub__(self: Interval[float], y: float) -> Interval[float]: ...
118116
@overload
119117
def __rsub__(
120118
self: Interval[_OrderableTimesT], y: Timedelta
@@ -124,31 +122,31 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
124122
self: Interval[int], y: _OrderableScalarT
125123
) -> Interval[_OrderableScalarT]: ...
126124
@overload
127-
def __rsub__(self: Interval[float], y: int | float) -> Interval[float]: ...
125+
def __rsub__(self: Interval[float], y: float) -> Interval[float]: ...
128126
@overload
129127
def __mul__(
130128
self: Interval[int], y: _OrderableScalarT
131129
) -> Interval[_OrderableScalarT]: ...
132130
@overload
133-
def __mul__(self: Interval[float], y: int | float) -> Interval[float]: ...
131+
def __mul__(self: Interval[float], y: float) -> Interval[float]: ...
134132
@overload
135133
def __rmul__(
136134
self: Interval[int], y: _OrderableScalarT
137135
) -> Interval[_OrderableScalarT]: ...
138136
@overload
139-
def __rmul__(self: Interval[float], y: int | float) -> Interval[float]: ...
137+
def __rmul__(self: Interval[float], y: float) -> Interval[float]: ...
140138
@overload
141139
def __truediv__(
142140
self: Interval[int], y: _OrderableScalarT
143141
) -> Interval[_OrderableScalarT]: ...
144142
@overload
145-
def __truediv__(self: Interval[float], y: int | float) -> Interval[float]: ...
143+
def __truediv__(self: Interval[float], y: float) -> Interval[float]: ...
146144
@overload
147145
def __floordiv__(
148146
self: Interval[int], y: _OrderableScalarT
149147
) -> Interval[_OrderableScalarT]: ...
150148
@overload
151-
def __floordiv__(self: Interval[float], y: int | float) -> Interval[float]: ...
149+
def __floordiv__(self: Interval[float], y: float) -> Interval[float]: ...
152150
def overlaps(self: Interval[_OrderableT], other: Interval[_OrderableT]) -> bool: ...
153151

154152
def intervals_to_interval_bounds(

pandas/_libs/join.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def asof_join_backward_on_X_by_Y(
5555
left_by_values: np.ndarray, # by_t[:]
5656
right_by_values: np.ndarray, # by_t[:]
5757
allow_exact_matches: bool = ...,
58-
tolerance: np.number | int | float | None = ...,
58+
tolerance: np.number | float | None = ...,
5959
use_hashtable: bool = ...,
6060
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
6161
def asof_join_forward_on_X_by_Y(
@@ -64,7 +64,7 @@ def asof_join_forward_on_X_by_Y(
6464
left_by_values: np.ndarray, # by_t[:]
6565
right_by_values: np.ndarray, # by_t[:]
6666
allow_exact_matches: bool = ...,
67-
tolerance: np.number | int | float | None = ...,
67+
tolerance: np.number | float | None = ...,
6868
use_hashtable: bool = ...,
6969
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
7070
def asof_join_nearest_on_X_by_Y(
@@ -73,6 +73,6 @@ def asof_join_nearest_on_X_by_Y(
7373
left_by_values: np.ndarray, # by_t[:]
7474
right_by_values: np.ndarray, # by_t[:]
7575
allow_exact_matches: bool = ...,
76-
tolerance: np.number | int | float | None = ...,
76+
tolerance: np.number | float | None = ...,
7777
use_hashtable: bool = ...,
7878
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...

pandas/_libs/json.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def dumps(
1212
date_unit: str = ...,
1313
iso_dates: bool = ...,
1414
default_handler: None
15-
| Callable[[Any], str | int | float | bool | list | dict | None] = ...,
15+
| Callable[[Any], str | float | bool | list | dict | None] = ...,
1616
) -> str: ...
1717
def loads(
1818
s: str,

pandas/_libs/tslibs/offsets.pyi

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
from datetime import (
42
datetime,
53
timedelta,

pandas/_libs/tslibs/timedeltas.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Timedelta(timedelta):
8686
cls: type[_S],
8787
value=...,
8888
unit: str = ...,
89-
**kwargs: int | float | np.integer | np.floating,
89+
**kwargs: float | np.integer | np.floating,
9090
) -> _S: ...
9191
# GH 46171
9292
# While Timedelta can return pd.NaT, having the constructor return
@@ -123,7 +123,7 @@ class Timedelta(timedelta):
123123
@overload # type: ignore[override]
124124
def __floordiv__(self, other: timedelta) -> int: ...
125125
@overload
126-
def __floordiv__(self, other: int | float) -> Timedelta: ...
126+
def __floordiv__(self, other: float) -> Timedelta: ...
127127
@overload
128128
def __floordiv__(
129129
self, other: npt.NDArray[np.timedelta64]

pandas/_libs/tslibs/timestamps.pyi

+1-7
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ class Timestamp(datetime):
3333
value: int # np.int64
3434
def __new__(
3535
cls: type[_DatetimeT],
36-
ts_input: int
37-
| np.integer
38-
| float
39-
| str
40-
| _date
41-
| datetime
42-
| np.datetime64 = ...,
36+
ts_input: np.integer | float | str | _date | datetime | np.datetime64 = ...,
4337
freq: int | None | str | BaseOffset = ...,
4438
tz: str | _tzinfo | None | int = ...,
4539
unit: str | int | None = ...,

pandas/_libs/writers.pyi

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
import numpy as np
42

53
from pandas._typing import ArrayLike

pandas/_typing.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282

8383
# scalars
8484

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

9494
TimestampConvertibleTypes = Union[
95-
"Timestamp", datetime, np.datetime64, int, np.int64, float, str
95+
"Timestamp", datetime, np.datetime64, np.int64, float, str
9696
]
9797
TimedeltaConvertibleTypes = Union[
98-
"Timedelta", timedelta, np.timedelta64, int, np.int64, float, str
98+
"Timedelta", timedelta, np.timedelta64, np.int64, float, str
9999
]
100100
Timezone = Union[str, tzinfo]
101101

@@ -126,7 +126,7 @@
126126
]
127127

128128
# dtypes
129-
NpDtype = Union[str, np.dtype, type_t[Union[str, float, int, complex, bool, object]]]
129+
NpDtype = Union[str, np.dtype, type_t[Union[str, complex, bool, object]]]
130130
Dtype = Union["ExtensionDtype", NpDtype]
131131
AstypeArg = Union["ExtensionDtype", "npt.DTypeLike"]
132132
# DtypeArg specifies all allowable dtypes in a functions its dtype argument

pandas/core/arrays/datetimelike.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2170,11 +2170,11 @@ def validate_periods(periods: None) -> None:
21702170

21712171

21722172
@overload
2173-
def validate_periods(periods: int | float) -> int:
2173+
def validate_periods(periods: float) -> int:
21742174
...
21752175

21762176

2177-
def validate_periods(periods: int | float | None) -> int | None:
2177+
def validate_periods(periods: float | None) -> int | None:
21782178
"""
21792179
If a `periods` argument is passed to the Datetime/Timedelta Array/Index
21802180
constructor, cast it to an integer.

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2563,7 +2563,7 @@ def to_stata(
25632563
compression: CompressionOptions = "infer",
25642564
storage_options: StorageOptions = None,
25652565
*,
2566-
value_labels: dict[Hashable, dict[float | int, str]] | None = None,
2566+
value_labels: dict[Hashable, dict[float, str]] | None = None,
25672567
) -> None:
25682568
"""
25692569
Export DataFrame object to Stata dta format.

pandas/core/nanops.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ def _get_counts_nanvar(
827827
axis: int | None,
828828
ddof: int,
829829
dtype: np.dtype = np.dtype(np.float64),
830-
) -> tuple[int | float | np.ndarray, int | float | np.ndarray]:
830+
) -> tuple[float | np.ndarray, float | np.ndarray]:
831831
"""
832832
Get the count of non-null values along an axis, accounting
833833
for degrees of freedom.
@@ -1414,7 +1414,7 @@ def _get_counts(
14141414
mask: npt.NDArray[np.bool_] | None,
14151415
axis: int | None,
14161416
dtype: np.dtype = np.dtype(np.float64),
1417-
) -> int | float | np.ndarray:
1417+
) -> float | np.ndarray:
14181418
"""
14191419
Get the count of non-null values along an axis
14201420

pandas/core/reshape/encoding.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def get_empty_frame(data) -> DataFrame:
272272

273273
if sparse:
274274

275-
fill_value: bool | float | int
275+
fill_value: bool | float
276276
if is_integer_dtype(dtype):
277277
fill_value = 0
278278
elif dtype == np.dtype(bool):

pandas/core/tools/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
# types used in annotations
9292

9393
ArrayConvertible = Union[List, Tuple, AnyArrayLike]
94-
Scalar = Union[int, float, str]
94+
Scalar = Union[float, str]
9595
DatetimeScalar = Union[Scalar, datetime]
9696

9797
DatetimeScalarOrArrayConvertible = Union[DatetimeScalar, ArrayConvertible]

pandas/core/tools/timedeltas.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
@overload
4747
def to_timedelta(
48-
arg: str | int | float | timedelta,
48+
arg: str | float | timedelta,
4949
unit: UnitChoices | None = ...,
5050
errors: DateTimeErrorChoices = ...,
5151
) -> Timedelta:

pandas/io/formats/excel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def build_number_format(self, props: Mapping[str, str]) -> dict[str, str | None]
331331

332332
def build_font(
333333
self, props: Mapping[str, str]
334-
) -> dict[str, bool | int | float | str | None]:
334+
) -> dict[str, bool | float | str | None]:
335335
font_names = self._get_font_names(props)
336336
decoration = self._get_decoration(props)
337337
return {

pandas/io/formats/format.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ def __init__(self, *args, **kwargs) -> None:
14471447
def _value_formatter(
14481448
self,
14491449
float_format: FloatFormatType | None = None,
1450-
threshold: float | int | None = None,
1450+
threshold: float | None = None,
14511451
) -> Callable:
14521452
"""Returns a function to be applied on each value to format it"""
14531453
# the float_format parameter supersedes self.float_format
@@ -2047,7 +2047,7 @@ def __init__(
20472047
self.accuracy = accuracy
20482048
self.use_eng_prefix = use_eng_prefix
20492049

2050-
def __call__(self, num: int | float) -> str:
2050+
def __call__(self, num: float) -> str:
20512051
"""
20522052
Formats a number in engineering notation, appending a letter
20532053
representing the power of 1000 of the original number. Some examples:

pandas/io/formats/info.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def _put_str(s: str | Dtype, space: int) -> str:
325325
return str(s)[:space].ljust(space)
326326

327327

328-
def _sizeof_fmt(num: int | float, size_qualifier: str) -> str:
328+
def _sizeof_fmt(num: float, size_qualifier: str) -> str:
329329
"""
330330
Return size in human readable format.
331331

pandas/io/formats/style.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3213,7 +3213,7 @@ def bar(
32133213
cmap: Any | None = None,
32143214
width: float = 100,
32153215
height: float = 100,
3216-
align: str | float | int | Callable = "mid",
3216+
align: str | float | Callable = "mid",
32173217
vmin: float | None = None,
32183218
vmax: float | None = None,
32193219
props: str = "width: 10em;",
@@ -4039,7 +4039,7 @@ def _highlight_value(data: DataFrame | Series, op: str, props: str) -> np.ndarra
40394039

40404040
def _bar(
40414041
data: NDFrame,
4042-
align: str | float | int | Callable,
4042+
align: str | float | Callable,
40434043
colors: str | list | tuple,
40444044
cmap: Any,
40454045
width: float,

pandas/io/formats/style_render.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
BaseFormatter = Union[str, Callable]
5050
ExtFormatter = Union[BaseFormatter, Dict[Any, Optional[BaseFormatter]]]
51-
CSSPair = Tuple[str, Union[str, int, float]]
51+
CSSPair = Tuple[str, Union[str, float]]
5252
CSSList = List[CSSPair]
5353
CSSProperties = Union[str, CSSList]
5454

@@ -2055,7 +2055,7 @@ def _parse_latex_header_span(
20552055
return display_val
20562056

20572057

2058-
def _parse_latex_options_strip(value: str | int | float, arg: str) -> str:
2058+
def _parse_latex_options_strip(value: str | float, arg: str) -> str:
20592059
"""
20602060
Strip a css_value which may have latex wrapping arguments, css comment identifiers,
20612061
and whitespaces, to a valid string for latex options parsing.

pandas/io/parsers/readers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ def validate_integer(name, val: None, min_val=...) -> None:
499499

500500

501501
@overload
502-
def validate_integer(name, val: int | float, min_val=...) -> int:
502+
def validate_integer(name, val: float, min_val=...) -> int:
503503
...
504504

505505

@@ -1910,7 +1910,7 @@ def _floatify_na_values(na_values):
19101910

19111911
def _stringify_na_values(na_values):
19121912
"""return a stringified and numeric for these values"""
1913-
result: list[int | str | float] = []
1913+
result: list[str | float] = []
19141914
for x in na_values:
19151915
result.append(str(x))
19161916
result.append(x)

0 commit comments

Comments
 (0)