Skip to content

Commit 9aac8e3

Browse files
authored
reportIncompatibleMethodOverride (#802)
* reportIncompatibleMethodOverride * BooleanDtype.na_value is a property * fix Timestamp.combine tests * unpin pyright
1 parent 05d6a52 commit 9aac8e3

30 files changed

+119
-218
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ ci:
33
autofix_prs: false
44
repos:
55
- repo: https://github.com/python/black
6-
rev: 23.9.1
6+
rev: 23.10.0
77
hooks:
88
- id: black
99
- repo: https://github.com/PyCQA/isort
1010
rev: 5.12.0
1111
hooks:
1212
- id: isort
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.0.292
14+
rev: v0.1.1
1515
hooks:
1616
- id: ruff
1717
args: [

pandas-stubs/_libs/tslibs/timedeltas.pyi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ UnitChoices: TypeAlias = (
101101
)
102102

103103
class Timedelta(timedelta):
104-
min: ClassVar[Timedelta]
105-
max: ClassVar[Timedelta]
106-
resolution: ClassVar[Timedelta]
104+
min: ClassVar[Timedelta] # pyright: ignore[reportIncompatibleVariableOverride]
105+
max: ClassVar[Timedelta] # pyright: ignore[reportIncompatibleVariableOverride]
106+
resolution: ClassVar[ # pyright: ignore[reportIncompatibleVariableOverride]
107+
Timedelta
108+
]
107109
value: int
108110
def __new__(
109111
cls,

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ _Nonexistent: TypeAlias = (
4747
)
4848

4949
class Timestamp(datetime):
50-
min: ClassVar[Timestamp]
51-
max: ClassVar[Timestamp]
50+
min: ClassVar[Timestamp] # pyright: ignore[reportIncompatibleVariableOverride]
51+
max: ClassVar[Timestamp] # pyright: ignore[reportIncompatibleVariableOverride]
5252

53-
resolution: ClassVar[Timedelta]
53+
resolution: ClassVar[ # pyright: ignore[reportIncompatibleVariableOverride]
54+
Timedelta
55+
]
5456
value: int
5557
def __new__(
5658
cls,
@@ -117,7 +119,7 @@ class Timestamp(datetime):
117119
def utcnow(cls) -> Self: ...
118120
# error: Signature of "combine" incompatible with supertype "datetime"
119121
@classmethod
120-
def combine(cls, date: _date, time: _time) -> datetime: ... # type: ignore[override]
122+
def combine(cls, date: _date, time: _time) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
121123
@classmethod
122124
def fromisoformat(cls, date_string: str) -> Self: ...
123125
def strftime(self, format: str) -> str: ...
@@ -132,7 +134,7 @@ class Timestamp(datetime):
132134
# Override since fold is more precise than datetime.replace(fold:int)
133135
# Here it is restricted to be 0 or 1 using a Literal
134136
# Violation of Liskov substitution principle
135-
def replace( # type:ignore[override]
137+
def replace( # type:ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
136138
self,
137139
year: int | None = ...,
138140
month: int | None = ...,
@@ -148,7 +150,7 @@ class Timestamp(datetime):
148150
def ctime(self) -> str: ...
149151
def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ...
150152
@classmethod
151-
def strptime(cls, date_string: Never, format: Never) -> Never: ... # type: ignore[override]
153+
def strptime(cls, date_string: Never, format: Never) -> Never: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
152154
def utcoffset(self) -> timedelta | None: ...
153155
def tzname(self) -> str | None: ...
154156
def dst(self) -> timedelta | None: ...
@@ -207,7 +209,7 @@ class Timestamp(datetime):
207209
@overload
208210
def __sub__(self, other: TimedeltaSeries) -> TimestampSeries: ...
209211
@overload
210-
def __sub__(
212+
def __sub__( # pyright: ignore[reportIncompatibleMethodOverride]
211213
self, other: npt.NDArray[np.timedelta64]
212214
) -> npt.NDArray[np.datetime64]: ...
213215
@overload

pandas-stubs/core/arraylike.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ from pandas._libs.ops_dispatch import (
77
)
88

99
class OpsMixin:
10-
def __eq__(self, other: object) -> Self: ... # type: ignore[override]
11-
def __ne__(self, other: object) -> Self: ... # type: ignore[override]
10+
def __eq__(self, other: object) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
11+
def __ne__(self, other: object) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
1212
def __lt__(self, other: Any) -> Self: ...
1313
def __le__(self, other: Any) -> Self: ...
1414
def __gt__(self, other: Any) -> Self: ...

pandas-stubs/core/arrays/boolean.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import ClassVar
2-
31
import numpy as np
42
from pandas.core.arrays.masked import BaseMaskedArray as BaseMaskedArray
53

@@ -9,7 +7,8 @@ from pandas._typing import type_t
97
from pandas.core.dtypes.base import ExtensionDtype as ExtensionDtype
108

119
class BooleanDtype(ExtensionDtype):
12-
na_value: ClassVar[NAType]
10+
@property
11+
def na_value(self) -> NAType: ...
1312
@classmethod
1413
def construct_array_type(cls) -> type_t[BooleanArray]: ...
1514

pandas-stubs/core/arrays/datetimelike.pyi

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ from pandas.core.arrays.base import (
55
ExtensionArray,
66
ExtensionOpsMixin,
77
)
8-
from typing_extensions import Self
98

109
from pandas._libs import (
1110
NaT as NaT,
1211
NaTType as NaTType,
1312
)
14-
from pandas._typing import TakeIndexer
1513

1614
class DatelikeOps:
1715
def strftime(self, date_format): ...
@@ -38,13 +36,12 @@ class DatetimeLikeArrayMixin(ExtensionOpsMixin, ExtensionArray):
3836
def size(self) -> int: ...
3937
def __len__(self) -> int: ...
4038
def __getitem__(self, key): ...
41-
def __setitem__(self, key: int | Sequence[int] | Sequence[bool] | slice, value) -> None: ... # type: ignore[override]
39+
def __setitem__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
40+
self, key: int | Sequence[int] | Sequence[bool] | slice, value
41+
) -> None: ...
4242
def astype(self, dtype, copy: bool = ...): ...
4343
def view(self, dtype=...): ...
4444
def unique(self): ...
45-
def take(
46-
self: Self, indices: TakeIndexer, *, allow_fill: bool = ..., fill_value=...
47-
) -> Self: ...
4845
def copy(self): ...
4946
def shift(self, periods: int = ..., fill_value=..., axis: int = ...): ...
5047
def searchsorted(self, value, side: str = ..., sorter=...): ...

pandas-stubs/core/arrays/datetimes.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DatetimeArray(DatetimeLikeArrayMixin, TimelikeOps, DatelikeOps):
1616
def __init__(self, values, dtype=..., freq=..., copy: bool = ...) -> None: ...
1717
# ignore in dtype() is from the pandas source
1818
@property
19-
def dtype(self) -> np.dtype | DatetimeTZDtype: ... # type: ignore[override]
19+
def dtype(self) -> np.dtype | DatetimeTZDtype: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
2020
@property
2121
def tz(self): ...
2222
@tz.setter

pandas-stubs/core/arrays/integer.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class _IntegerDtype(ExtensionDtype):
1414
def construct_array_type(cls) -> type[IntegerArray]: ...
1515

1616
class IntegerArray(BaseMaskedArray):
17-
def dtype(self): ...
17+
@property
18+
def dtype(self) -> _IntegerDtype: ...
1819
def __init__(self, values, mask, copy: bool = ...) -> None: ...
1920
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): ...
2021
def __setitem__(self, key, value) -> None: ...

pandas-stubs/core/arrays/interval.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ from pandas._typing import (
2020
)
2121

2222
class IntervalArray(IntervalMixin, ExtensionArray):
23-
ndim: int = ...
2423
can_hold_na: bool = ...
2524
def __new__(
2625
cls, data, closed=..., dtype=..., copy: bool = ..., verify_integrity: bool = ...
@@ -50,7 +49,7 @@ class IntervalArray(IntervalMixin, ExtensionArray):
5049
@property
5150
def size(self) -> int: ...
5251
def shift(self, periods: int = ..., fill_value: object = ...) -> IntervalArray: ...
53-
def take( # type: ignore[override]
52+
def take( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
5453
self: Self,
5554
indices: TakeIndexer,
5655
*,

pandas-stubs/core/arrays/masked.pyi

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ from pandas.core.arrays import (
66

77
from pandas._typing import (
88
Scalar,
9-
TakeIndexer,
109
npt,
1110
)
1211

@@ -27,8 +26,5 @@ class BaseMaskedArray(ExtensionArray, ExtensionOpsMixin):
2726
def isna(self): ...
2827
@property
2928
def nbytes(self) -> int: ...
30-
def take(
31-
self, indexer: TakeIndexer, allow_fill: bool = ..., fill_value=...
32-
) -> BaseMaskedArray: ...
3329
def copy(self): ...
3430
def value_counts(self, dropna: bool = ...): ...

pandas-stubs/core/arrays/period.pyi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
from collections.abc import Sequence
22

33
import numpy as np
4+
from pandas import PeriodDtype
45
from pandas.core.arrays.datetimelike import (
56
DatelikeOps,
67
DatetimeLikeArrayMixin,
78
)
89

910
from pandas._libs.tslibs import Timestamp
10-
from pandas._libs.tslibs.period import Period as Period
11+
from pandas._libs.tslibs.period import Period
1112

12-
from pandas.tseries.offsets import Tick as Tick
13+
from pandas.tseries.offsets import Tick
1314

1415
class PeriodArray(DatetimeLikeArrayMixin, DatelikeOps):
1516
__array_priority__: int = ...
1617
def __init__(self, values, freq=..., dtype=..., copy: bool = ...) -> None: ...
17-
def dtype(self): ...
18+
@property
19+
def dtype(self) -> PeriodDtype: ...
1820
def __array__(self, dtype=...) -> np.ndarray: ...
1921
def __arrow_array__(self, type=...): ...
2022
year: int = ...

pandas-stubs/core/arrays/sparse/array.pyi

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ from pandas.core.arrays import (
44
ExtensionOpsMixin,
55
)
66

7-
from pandas._typing import TakeIndexer
8-
97
class SparseArray(ExtensionArray, ExtensionOpsMixin):
108
def __init__(
119
self,
@@ -43,15 +41,8 @@ class SparseArray(ExtensionArray, ExtensionOpsMixin):
4341
def fillna(self, value=..., method=..., limit=...): ...
4442
def shift(self, periods: int = ..., fill_value=...): ...
4543
def unique(self): ...
46-
def factorize(
47-
self, na_sentinel: int = ..., use_na_sentinel: bool = ...
48-
) -> tuple[np.ndarray, SparseArray]: ...
4944
def value_counts(self, dropna: bool = ...): ...
5045
def __getitem__(self, key): ...
51-
def take(
52-
self, indices: TakeIndexer, *, allow_fill: bool = ..., fill_value=...
53-
) -> SparseArray: ...
54-
def searchsorted(self, v, side: str = ..., sorter=...): ...
5546
def copy(self): ...
5647
def astype(self, dtype=..., copy: bool = ...): ...
5748
def map(self, mapper): ...

pandas-stubs/core/computation/pytables.pyi

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,18 @@ class FilterBinOp(BinOp):
5858
filter: tuple[Any, Any, Index] | None = ...
5959
def invert(self): ...
6060
def format(self): ...
61-
def evaluate(self): ...
6261
def generate_filter_op(self, invert: bool = ...): ...
6362

6463
class JointFilterBinOp(FilterBinOp):
6564
def format(self) -> None: ...
66-
def evaluate(self): ...
6765

6866
class ConditionBinOp(BinOp):
6967
def invert(self) -> None: ...
7068
def format(self): ...
7169
condition = ...
72-
def evaluate(self): ...
7370

7471
class JointConditionBinOp(ConditionBinOp):
7572
condition = ...
76-
def evaluate(self): ...
7773

7874
class UnaryOp(ops.UnaryOp):
7975
def prune(self, klass): ...

pandas-stubs/core/generic.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ _bool = bool
5454
_str = str
5555

5656
class NDFrame(indexing.IndexingMixin):
57-
__hash__: ClassVar[None] # type: ignore[assignment]
57+
__hash__: ClassVar[None] # type: ignore[assignment] # pyright: ignore[reportIncompatibleMethodOverride]
5858

5959
def set_flags(
6060
self,

pandas-stubs/core/indexes/base.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class Index(IndexOpsMixin[S1]):
317317
def is_mixed(self) -> bool: ...
318318
def holds_integer(self): ...
319319
@property
320-
def inferred_type(self): ...
320+
def inferred_type(self) -> _str: ...
321321
def __reduce__(self): ...
322322
@property
323323
def hasnans(self) -> bool: ...
@@ -412,13 +412,13 @@ class Index(IndexOpsMixin[S1]):
412412
@property
413413
def shape(self) -> tuple[int, ...]: ...
414414
# Extra methods from old stubs
415-
def __eq__(self, other: object) -> np_ndarray_bool: ... # type: ignore[override]
415+
def __eq__(self, other: object) -> np_ndarray_bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
416416
def __iter__(self) -> Iterator[S1]: ...
417-
def __ne__(self, other: object) -> np_ndarray_bool: ... # type: ignore[override]
418-
def __le__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override]
419-
def __ge__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override]
420-
def __lt__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override]
421-
def __gt__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override]
417+
def __ne__(self, other: object) -> np_ndarray_bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
418+
def __le__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
419+
def __ge__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
420+
def __lt__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
421+
def __gt__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
422422
# overwrite inherited methods from OpsMixin
423423
@overload
424424
def __mul__( # type: ignore[misc]

pandas-stubs/core/indexes/category.pyi

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,10 @@ class CategoricalIndex(ExtensionIndex[S1], accessor.PandasDelegate):
4141
def is_monotonic_decreasing(self) -> bool: ...
4242
def unique(self, level=...): ...
4343
def duplicated(self, keep: Literal["first", "last", False] = ...): ...
44-
def get_loc(self, key): ...
45-
def get_value(self, seriesArrayLike, key): ...
4644
def where(self, cond, other=...): ...
4745
def reindex(self, target, method=..., level=..., limit=..., tolerance=...): ...
4846
def get_indexer(self, target, method=..., limit=..., tolerance=...): ...
4947
def get_indexer_non_unique(self, target): ...
5048
def take_nd(self, *args, **kwargs): ...
51-
def map(self, mapper): ...
5249
def delete(self, loc): ...
5350
def insert(self, loc, item): ...

pandas-stubs/core/indexes/datetimelike.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DatetimeIndexOpsMixin(ExtensionIndex[S1]):
1515
def argmin(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
1616
def max(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
1717
def argmax(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
18-
def __rsub__( # type: ignore[override]
18+
def __rsub__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
1919
self, other: DatetimeIndexOpsMixin
2020
) -> TimedeltaIndex: ...
2121

pandas-stubs/core/indexes/datetimes.pyi

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,11 @@ class DatetimeIndex(DatetimeTimedeltaMixin[Timestamp], DatetimeIndexProperties):
6666
def __sub__(self, other: Timedelta | TimedeltaIndex) -> DatetimeIndex: ...
6767
@overload
6868
def __sub__(self, other: Timestamp | DatetimeIndex) -> TimedeltaIndex: ...
69-
# overload needed because Index.to_series() and DatetimeIndex.to_series() have
70-
# different arguments
71-
def to_series(self, keep_tz=..., index=..., name=...) -> TimestampSeries: ... # type: ignore[override]
69+
def to_series(self, index=..., name=...) -> TimestampSeries: ...
7270
def snap(self, freq: str = ...): ...
7371
def get_value(self, series, key): ...
74-
def get_loc(self, key, tolerance=...): ...
7572
def slice_indexer(self, start=..., end=..., step=...): ...
7673
def searchsorted(self, value, side: str = ..., sorter=...): ...
77-
def is_type_compatible(self, typ) -> bool: ...
7874
@property
7975
def inferred_type(self) -> str: ...
8076
def insert(self, loc, item): ...

pandas-stubs/core/indexes/frozen.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ class FrozenList(list):
66
def __eq__(self, other) -> bool: ...
77
def __mul__(self, other): ...
88
def __reduce__(self): ...
9-
def __hash__(self) -> int: ... # type: ignore[override]
9+
def __hash__(self) -> int: ... # type: ignore[override] # pyright: ignore[reportIncompatibleVariableOverride]

pandas-stubs/core/indexes/interval.pyi

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ class IntervalIndex(ExtensionIndex[IntervalT], IntervalMixin):
259259
| np_ndarray_bool,
260260
) -> IntervalIndex[IntervalT]: ...
261261
@overload
262-
def __getitem__(self, idx: int) -> IntervalT: ...
262+
def __getitem__( # pyright: ignore[reportIncompatibleMethodOverride]
263+
self, idx: int
264+
) -> IntervalT: ...
263265
@property
264266
def is_all_dates(self) -> bool: ...
265267
@overload # type: ignore[override]
@@ -291,13 +293,17 @@ class IntervalIndex(ExtensionIndex[IntervalT], IntervalMixin):
291293
@overload
292294
def __eq__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ... # type: ignore[misc]
293295
@overload
294-
def __eq__(self, other: object) -> Literal[False]: ...
296+
def __eq__( # pyright: ignore[reportIncompatibleMethodOverride]
297+
self, other: object
298+
) -> Literal[False]: ...
295299
@overload # type: ignore[override]
296300
def __ne__(self, other: IntervalT | IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[misc] # pyright: ignore[reportOverlappingOverload]
297301
@overload
298302
def __ne__(self, other: pd.Series[IntervalT]) -> pd.Series[bool]: ... # type: ignore[misc]
299303
@overload
300-
def __ne__(self, other: object) -> Literal[True]: ...
304+
def __ne__( # pyright: ignore[reportIncompatibleMethodOverride]
305+
self, other: object
306+
) -> Literal[True]: ...
301307

302308
# misc here because int and float overlap but interval has distinct types
303309
# int gets hit first and so the correct type is returned

0 commit comments

Comments
 (0)