Skip to content

Commit 9383884

Browse files
authored
TYP: future annotations (#151)
* automatic * manual * flake8-pyi Y022 * flake8 * test * Revert "test" This reverts commit 188c4d9. * mypy 0.971 compatible * Revert "Revert "test"" This reverts commit edb4539. * type_t * str * Revert "str" This reverts commit 40739c2. * npt + _str
1 parent 5f47ff7 commit 9383884

File tree

225 files changed

+2880
-2966
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

225 files changed

+2880
-2966
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ jobs:
77
runs-on: ${{ matrix.os }}
88
timeout-minutes: 10
99
strategy:
10+
fail-fast: false
1011
matrix:
1112
os: [ubuntu-latest, windows-latest, macos-latest]
1213
python-version: ['3.8', '3.9', '3.10']

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
- id: pyupgrade
1717
types_or: [python, pyi]
1818
types: [text] # overwrite types: [python]
19-
args: [--py38-plus, --keep-runtime-typing]
19+
args: [--py38-plus]
2020
- repo: https://github.com/PyCQA/flake8
2121
rev: 4.0.1
2222
hooks:
@@ -30,7 +30,7 @@ repos:
3030
- flake8-pyi==22.5.1
3131
types: [pyi]
3232
args: [
33-
--ignore=E301 E302 E305 E402 E501 E701 E704 F401 F811 W503 Y019 Y022 Y026 Y027 Y034 Y037,
33+
--ignore=E301 E302 E305 E402 E501 E701 E704 F401 F811 W503 Y019 Y026 Y027 Y034 Y037,
3434
# TypeVars in private files are already private
3535
--per-file-ignores=_*.pyi:Y001
3636
]

pandas-stubs/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import pandas.testing as testing
24

35
from . import (

pandas-stubs/_config/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from .config import (
24
describe_option as describe_option,
35
get_option as get_option,

pandas-stubs/_config/config.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from contextlib import ContextDecorator
24
from typing import (
35
Any,

pandas-stubs/_libs/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from .interval import Interval as Interval
24
from .tslibs import (
35
NaT as NaT,

pandas-stubs/_libs/indexing.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
class _NDFrameIndexerBase:
24
def __init__(self, name: str, obj: object) -> None: ...
35
@property

pandas-stubs/_libs/interval.pyi

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ from typing import (
44
Any,
55
Generic,
66
TypeVar,
7-
Union,
87
overload,
98
)
109

@@ -79,9 +78,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
7978
@overload
8079
def __contains__(self: Interval[_OrderableTimesT], _OrderableTimesT) -> bool: ...
8180
@overload
82-
def __contains__(
83-
self: Interval[_OrderableScalarT], key: Union[int, float]
84-
) -> bool: ...
81+
def __contains__(self: Interval[_OrderableScalarT], key: int | float) -> bool: ...
8582
@overload
8683
def __add__(
8784
self: Interval[_OrderableTimesT], y: Timedelta
@@ -91,7 +88,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
9188
self: Interval[int], y: _OrderableScalarT
9289
) -> Interval[_OrderableScalarT]: ...
9390
@overload
94-
def __add__(self: Interval[float], y: Union[int, float]) -> Interval[float]: ...
91+
def __add__(self: Interval[float], y: int | float) -> Interval[float]: ...
9592
@overload
9693
def __radd__(
9794
self: Interval[_OrderableTimesT], y: Timedelta
@@ -101,7 +98,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
10198
self: Interval[int], y: _OrderableScalarT
10299
) -> Interval[_OrderableScalarT]: ...
103100
@overload
104-
def __radd__(self: Interval[float], y: Union[int, float]) -> Interval[float]: ...
101+
def __radd__(self: Interval[float], y: int | float) -> Interval[float]: ...
105102
@overload
106103
def __sub__(
107104
self: Interval[_OrderableTimesT], y: Timedelta
@@ -111,7 +108,7 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
111108
self: Interval[int], y: _OrderableScalarT
112109
) -> Interval[_OrderableScalarT]: ...
113110
@overload
114-
def __sub__(self: Interval[float], y: Union[int, float]) -> Interval[float]: ...
111+
def __sub__(self: Interval[float], y: int | float) -> Interval[float]: ...
115112
@overload
116113
def __rsub__(
117114
self: Interval[_OrderableTimesT], y: Timedelta
@@ -121,33 +118,31 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
121118
self: Interval[int], y: _OrderableScalarT
122119
) -> Interval[_OrderableScalarT]: ...
123120
@overload
124-
def __rsub__(self: Interval[float], y: Union[int, float]) -> Interval[float]: ...
121+
def __rsub__(self: Interval[float], y: int | float) -> Interval[float]: ...
125122
@overload
126123
def __mul__(
127124
self: Interval[int], y: _OrderableScalarT
128125
) -> Interval[_OrderableScalarT]: ...
129126
@overload
130-
def __mul__(self: Interval[float], y: Union[int, float]) -> Interval[float]: ...
127+
def __mul__(self: Interval[float], y: int | float) -> Interval[float]: ...
131128
@overload
132129
def __rmul__(
133130
self: Interval[int], y: _OrderableScalarT
134131
) -> Interval[_OrderableScalarT]: ...
135132
@overload
136-
def __rmul__(self: Interval[float], y: Union[int, float]) -> Interval[float]: ...
133+
def __rmul__(self: Interval[float], y: int | float) -> Interval[float]: ...
137134
@overload
138135
def __truediv__(
139136
self: Interval[int], y: _OrderableScalarT
140137
) -> Interval[_OrderableScalarT]: ...
141138
@overload
142-
def __truediv__(self: Interval[float], y: Union[int, float]) -> Interval[float]: ...
139+
def __truediv__(self: Interval[float], y: int | float) -> Interval[float]: ...
143140
@overload
144141
def __floordiv__(
145142
self: Interval[int], y: _OrderableScalarT
146143
) -> Interval[_OrderableScalarT]: ...
147144
@overload
148-
def __floordiv__(
149-
self: Interval[float], y: Union[int, float]
150-
) -> Interval[float]: ...
145+
def __floordiv__(self: Interval[float], y: int | float) -> Interval[float]: ...
151146
def overlaps(self: Interval[_OrderableT], other: Interval[_OrderableT]) -> bool: ...
152147

153148
def intervals_to_interval_bounds(

pandas-stubs/_libs/json.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
def decode(*args, **kwargs): ...
24
def dumps(*args, **kwargs): ...
35
def encode(*args, **kwargs): ...

pandas-stubs/_libs/lib.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
no_default = None
24

35
def infer_dtype(value: object, skipna: bool = ...) -> str: ...

pandas-stubs/_libs/missing.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
from typing import Union
4-
53
class NAType:
64
def __new__(cls, *args, **kwargs) -> NAType: ...
75
def __format__(self, format_spec: str) -> str: ...
@@ -36,9 +34,9 @@ class NAType:
3634
def __invert__(self, other) -> NAType: ...
3735
def __pow__(self, other) -> NAType: ...
3836
def __rpow__(self, other) -> NAType: ...
39-
def __and__(self, other) -> Union[None, NAType]: ...
37+
def __and__(self, other) -> NAType | None: ...
4038
__rand__ = __and__
41-
def __or__(self, other) -> Union[bool, NAType]: ...
39+
def __or__(self, other) -> bool | NAType: ...
4240
__ror__ = __or__
4341
def __xor__(self, other) -> NAType: ...
4442
__rxor__ = __xor__

pandas-stubs/_libs/ops_dispatch.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
DISPATCHED_UFUNCS = ...
24
REVERSED_NAMES = ...
35
UFUNC_ALIASES = ...

pandas-stubs/_libs/properties.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import Callable
24

35
class CachedProperty:

pandas-stubs/_libs/sparse.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
class SparseIndex: ...
24
class BlockIndex(SparseIndex): ...
35
class IntIndex(SparseIndex): ...

pandas-stubs/_libs/tslibs/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
__all__ = [
24
"Period",
35
"Timestamp",

pandas-stubs/_libs/tslibs/base.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from datetime import datetime
24

35
class ABCTimestamp(datetime): ...

pandas-stubs/_libs/tslibs/ccalendar.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import Sequence
24

35
def dayofweek(y: int, m: int, d: int) -> int: ...

pandas-stubs/_libs/tslibs/conversion.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from datetime import datetime
24

35
def localize_pydatetime(dt: datetime, tz: object) -> datetime: ...

pandas-stubs/_libs/tslibs/dtypes.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from __future__ import annotations
2+
13
from enum import Enum
2-
from typing import Dict
34

45
from .offsets import BaseOffset
56

@@ -13,7 +14,7 @@ class PeriodDtypeBase:
1314
@classmethod
1415
def from_date_offset(cls, offset: BaseOffset) -> PeriodDtypeBase: ...
1516

16-
attrname_to_abbrevs: Dict[str, str]
17+
attrname_to_abbrevs: dict[str, str]
1718

1819
class FreqGroup:
1920
FR_ANN: int

pandas-stubs/_libs/tslibs/nattype.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from datetime import (
24
datetime,
35
timedelta,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
from __future__ import annotations
2+
13
class OutOfBoundsDatetime(ValueError): ...

pandas-stubs/_libs/tslibs/offsets.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class _CustomBusinessMonth(BusinessMixin):
204204
n: int = ...,
205205
normalize: bool = ...,
206206
offset: timedelta = ...,
207-
holidays: None | list = ...,
207+
holidays: list | None = ...,
208208
): ...
209209

210210
class CustomBusinessDay(BusinessDay):
@@ -224,7 +224,7 @@ class CustomBusinessHour(BusinessHour):
224224
start: str = ...,
225225
end: str = ...,
226226
offset: timedelta = ...,
227-
holidays: None | list = ...,
227+
holidays: list | None = ...,
228228
): ...
229229

230230
class CustomBusinessMonthEnd(_CustomBusinessMonth): ...

pandas-stubs/_libs/tslibs/parsing.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import Any
24

35
def parse_time_string(*args, **kwargs) -> Any: ...
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import Any
24

35
def array_strptime(*args, **kwargs) -> Any: ...

pandas-stubs/_libs/tslibs/timedeltas.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
from __future__ import annotations
2+
13
from datetime import timedelta
24
from typing import (
35
ClassVar,
46
Literal,
5-
Type,
67
TypeVar,
78
overload,
89
)
@@ -80,7 +81,7 @@ class Timedelta(timedelta):
8081
resolution: ClassVar[Timedelta]
8182
value: int # np.int64
8283
def __new__(
83-
cls: Type[_S],
84+
cls: type[_S],
8485
value=...,
8586
unit: str = ...,
8687
**kwargs: int | float | np.integer | np.floating,
@@ -130,7 +131,7 @@ class Timedelta(timedelta):
130131
@overload
131132
def __rfloordiv__(self, other: timedelta | str) -> int: ...
132133
@overload
133-
def __rfloordiv__(self, other: None | NaTType) -> NaTType: ...
134+
def __rfloordiv__(self, other: NaTType | None) -> NaTType: ...
134135
@overload
135136
def __rfloordiv__(self, other: np.ndarray) -> npt.NDArray[np.timedelta64]: ...
136137
@overload

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from datetime import (
24
date as _date,
35
datetime,
@@ -40,8 +42,8 @@ class Timestamp(datetime):
4042
| _date
4143
| datetime
4244
| np.datetime64 = ...,
43-
freq: int | None | str | BaseOffset = ...,
44-
tz: str | _tzinfo | None | int = ...,
45+
freq: int | str | BaseOffset | None = ...,
46+
tz: str | _tzinfo | int | None = ...,
4547
unit: str | int | None = ...,
4648
year: int | None = ...,
4749
month: int | None = ...,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
from __future__ import annotations
2+
13
def tz_convert_from_utc_single(val: int, tz: str) -> int: ...
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
from typing import (
2-
List,
3-
Optional,
4-
Sequence,
5-
)
1+
from __future__ import annotations
2+
3+
from typing import Sequence
64

75
import numpy as np
86

97
from .dtypes import Resolution
108

119
def normalize_i8_timestamps(
12-
stamps: Sequence[int], tz: Optional[str] = ...
13-
) -> List[int]: ...
14-
def is_date_array_normalized(
15-
stamps: Sequence[int], tz: Optional[str] = ...
16-
) -> bool: ...
10+
stamps: Sequence[int], tz: str | None = ...
11+
) -> list[int]: ...
12+
def is_date_array_normalized(stamps: Sequence[int], tz: str | None = ...) -> bool: ...
1713
def dt64arr_to_periodarr(
18-
stamps: Sequence[int], freq: int, tz: Optional[str] = ...
19-
) -> List[int]: ...
14+
stamps: Sequence[int], freq: int, tz: str | None = ...
15+
) -> list[int]: ...
2016
def ints_to_pydatetime(
2117
arr: Sequence[int], tz: str = ..., freq: str = ..., fold: bool = ..., box: str = ...
2218
) -> np.ndarray: ...
23-
def get_resolution(stamps: Sequence[int], tz: Optional[str] = ...) -> Resolution: ...
19+
def get_resolution(stamps: Sequence[int], tz: str | None = ...) -> Resolution: ...

0 commit comments

Comments
 (0)