Skip to content

Commit 9c20865

Browse files
authored
Support pyright 376 (#979)
* Revert "remove pyright overrides not needed with pyright 1.1.374 (#967)" This reverts commit 458ecb4. * fix matplotlib tests for Windows 11 * lock numpy up to 2.0.1
1 parent ce546ff commit 9c20865

File tree

5 files changed

+59
-12
lines changed

5 files changed

+59
-12
lines changed

conftest.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import gc
2+
3+
import pytest
4+
5+
6+
@pytest.fixture
7+
def mpl_cleanup():
8+
"""
9+
Ensure Matplotlib is cleaned up around a test.
10+
11+
Before a test is run:
12+
13+
1) Set the backend to "template" to avoid requiring a GUI.
14+
15+
After a test is run:
16+
17+
1) Reset units registry
18+
2) Reset rc_context
19+
3) Close all figures
20+
21+
See matplotlib/testing/decorators.py#L24.
22+
"""
23+
mpl = pytest.importorskip("matplotlib")
24+
mpl_units = pytest.importorskip("matplotlib.units")
25+
plt = pytest.importorskip("matplotlib.pyplot")
26+
orig_units_registry = mpl_units.registry.copy()
27+
try:
28+
with mpl.rc_context():
29+
mpl.use("template")
30+
yield
31+
finally:
32+
mpl_units.registry.clear()
33+
mpl_units.registry.update(orig_units_registry)
34+
plt.close("all")
35+
# https://matplotlib.org/stable/users/prev_whats_new/whats_new_3.6.0.html#garbage-collection-is-no-longer-run-on-figure-close
36+
gc.collect(1)

pandas-stubs/core/indexes/datetimelike.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DatetimeIndexOpsMixin(ExtensionIndex[S1]):
1919
def argmin(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
2020
def max(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
2121
def argmax(self, axis=..., skipna: bool = ..., *args, **kwargs): ...
22-
def __rsub__( # type: ignore[override]
22+
def __rsub__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
2323
self, other: DatetimeIndexOpsMixin
2424
) -> TimedeltaIndex: ...
2525

pandas-stubs/core/series.pyi

+16-10
Original file line numberDiff line numberDiff line change
@@ -1506,21 +1506,23 @@ class Series(IndexOpsMixin[S1], NDFrame):
15061506
self, other: bool | list[bool] | list[int] | np_ndarray_bool | Series[bool]
15071507
) -> Series[bool]: ...
15081508
@overload
1509-
def __and__(self, other: int | np_ndarray_anyint | Series[int]) -> Series[int]: ...
1509+
def __and__( # pyright: ignore[reportIncompatibleMethodOverride]
1510+
self, other: int | np_ndarray_anyint | Series[int]
1511+
) -> Series[int]: ...
15101512
# def __array__(self, dtype: Optional[_bool] = ...) -> _np_ndarray
15111513
def __div__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ...
15121514
def __eq__(self, other: object) -> Series[_bool]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
15131515
def __floordiv__(self, other: num | _ListLike | Series[S1]) -> Series[int]: ...
1514-
def __ge__( # type: ignore[override]
1516+
def __ge__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
15151517
self, other: S1 | _ListLike | Series[S1] | datetime | timedelta | date
15161518
) -> Series[_bool]: ...
1517-
def __gt__( # type: ignore[override]
1519+
def __gt__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
15181520
self, other: S1 | _ListLike | Series[S1] | datetime | timedelta | date
15191521
) -> Series[_bool]: ...
1520-
def __le__( # type: ignore[override]
1522+
def __le__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
15211523
self, other: S1 | _ListLike | Series[S1] | datetime | timedelta | date
15221524
) -> Series[_bool]: ...
1523-
def __lt__( # type: ignore[override]
1525+
def __lt__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
15241526
self, other: S1 | _ListLike | Series[S1] | datetime | timedelta | date
15251527
) -> Series[_bool]: ...
15261528
@overload
@@ -1538,7 +1540,9 @@ class Series(IndexOpsMixin[S1], NDFrame):
15381540
self, other: bool | list[bool] | list[int] | np_ndarray_bool | Series[bool]
15391541
) -> Series[bool]: ...
15401542
@overload
1541-
def __or__(self, other: int | np_ndarray_anyint | Series[int]) -> Series[int]: ...
1543+
def __or__( # pyright: ignore[reportIncompatibleMethodOverride]
1544+
self, other: int | np_ndarray_anyint | Series[int]
1545+
) -> Series[int]: ...
15421546
@overload
15431547
def __radd__(self, other: S1 | Series[S1]) -> Self: ...
15441548
@overload
@@ -1549,7 +1553,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
15491553
self, other: bool | list[bool] | list[int] | np_ndarray_bool | Series[bool]
15501554
) -> Series[bool]: ...
15511555
@overload
1552-
def __rand__(self, other: int | np_ndarray_anyint | Series[int]) -> Series[int]: ... # type: ignore[misc]
1556+
def __rand__(self, other: int | np_ndarray_anyint | Series[int]) -> Series[int]: ... # type: ignore[misc] # pyright: ignore[reportIncompatibleMethodOverride]
15531557
def __rdiv__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ...
15541558
def __rdivmod__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
15551559
def __rfloordiv__(self, other: num | _ListLike | Series[S1]) -> Series[S1]: ...
@@ -1568,7 +1572,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
15681572
self, other: bool | list[bool] | list[int] | np_ndarray_bool | Series[bool]
15691573
) -> Series[bool]: ...
15701574
@overload
1571-
def __ror__(self, other: int | np_ndarray_anyint | Series[int]) -> Series[int]: ... # type: ignore[misc]
1575+
def __ror__(self, other: int | np_ndarray_anyint | Series[int]) -> Series[int]: ... # type: ignore[misc] # pyright: ignore[reportIncompatibleMethodOverride]
15721576
def __rsub__(self, other: num | _ListLike | Series[S1]) -> Series: ...
15731577
def __rtruediv__(self, other: num | _ListLike | Series[S1]) -> Series: ...
15741578
# ignore needed for mypy as we want different results based on the arguments
@@ -1577,7 +1581,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
15771581
self, other: bool | list[bool] | list[int] | np_ndarray_bool | Series[bool]
15781582
) -> Series[bool]: ...
15791583
@overload
1580-
def __rxor__(self, other: int | np_ndarray_anyint | Series[int]) -> Series[int]: ... # type: ignore[misc]
1584+
def __rxor__(self, other: int | np_ndarray_anyint | Series[int]) -> Series[int]: ... # type: ignore[misc] # pyright: ignore[reportIncompatibleMethodOverride]
15811585
@overload
15821586
def __sub__(
15831587
self: Series[Timestamp],
@@ -1601,7 +1605,9 @@ class Series(IndexOpsMixin[S1], NDFrame):
16011605
self, other: bool | list[bool] | list[int] | np_ndarray_bool | Series[bool]
16021606
) -> Series[bool]: ...
16031607
@overload
1604-
def __xor__(self, other: int | np_ndarray_anyint | Series[int]) -> Series[int]: ...
1608+
def __xor__( # pyright: ignore[reportIncompatibleMethodOverride]
1609+
self, other: int | np_ndarray_anyint | Series[int]
1610+
) -> Series[int]: ...
16051611
def __invert__(self) -> Series[bool]: ...
16061612
# properties
16071613
# @property

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ packages = [{ "include" = "pandas-stubs" }]
3030
[tool.poetry.dependencies]
3131
python = ">=3.9"
3232
types-pytz = ">= 2022.1.1"
33-
numpy = ">= 1.23.5"
33+
numpy = ">= 1.23.5, <= 2.0.1"
3434

3535
[tool.poetry.group.dev.dependencies]
3636
mypy = "1.10.1"

tests/test_plotting.py

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
)
2525

2626

27+
@pytest.fixture(autouse=True)
28+
def autouse_mpl_cleanup(mpl_cleanup):
29+
pass
30+
31+
2732
@pytest.fixture
2833
def close_figures():
2934
plt.close("all")

0 commit comments

Comments
 (0)