Skip to content

Commit d5c32e0

Browse files
Merge branch 'pandas-dev:main' into test_issue
2 parents 99a3861 + af9b633 commit d5c32e0

Some content is hidden

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

55 files changed

+2030
-614
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pip install pandas-stubs
101101

102102
## Installation from sources
103103

104-
- Make sure you have `python >= 3.9` installed.
104+
- Make sure you have `python >= 3.10` installed.
105105
- Install poetry
106106

107107
```sh

conftest.py

Lines changed: 36 additions & 0 deletions
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)

docs/release_procedure.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77

88
```shell
99
rm dist/*
10-
poetry publish --build # you will get prompted for your pypi username/password
10+
poetry build
11+
twine upload dist/* # Requires having the pypi API token allowing uploads
1112
git commit -a -m "Version a.b.c.yymmdd"
1213
git push upstream main
1314
git tag va.b.c.yymmdd
1415
git push upstream --tags
1516
```
1617

1718
The conda bots will recognize that a new version has been uploaded to pypi, and generate a pull request sent to the maintainers to approve it.
18-
19-
Note - Changes will need to be made to use pypi API tokens in the near future.

docs/setup.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
## Set Up Environment
22

3-
- Make sure you have `python >= 3.9` installed.
4-
- Install poetry: `pip install 'poetry>=1.2'`
3+
- Make sure you have `python >= 3.10` installed.
4+
- If using macOS, you may need to install `hdf5` (e.g., via `brew install hdf5`).
5+
- Install poetry: `pip install 'poetry>=1.8'`
56
- Install the project dependencies: `poetry update`
67
- Enter the virtual environment: `poetry shell`
78
- Run all tests: `poe test_all`

docs/tests.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Here are the most important options. Fore more details, please use `poe --help`.
66

77
- Run all tests (against both source and installed stubs): `poe test_all`
8-
- Run tests against the source code: `poe test`
8+
- Run tests against the source code: `poe test`
99
- Run only mypy: `poe mypy`
1010
- Run only pyright: `poe pyright`
1111
- Run only pytest: `poe pytest`
@@ -20,3 +20,9 @@ The following tests are **optional**. Some of them are run by the CI but it is o
2020
- Use mypy nightly to validate the annotations: `poe mypy --mypy_nightly`
2121
- Use pyright in full strict mode: `poe pyright_strict`
2222
- Run stubtest to compare the installed pandas-stubs against pandas (this will fail): `poe stubtest`. If you have created an allowlist to ignore certain errors: `poe stubtest path_to_the_allow_list`
23+
24+
Among the tests above, the following can be run directly during a PR by commenting in the discussion.
25+
26+
- Run pytest against pandas nightly by commenting `/pandas_nightly`
27+
- Use mypy nightly to validate the annotations by commenting `/mypy_nightly`
28+
- Use pyright in full strict mode by commenting `/pyright_strict`

pandas-stubs/_libs/interval.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ class Interval(IntervalMixin, Generic[_OrderableT]):
201201
@overload
202202
def __eq__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
203203
@overload
204-
def __eq__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[overload-overlap]
204+
def __eq__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ...
205205
@overload
206206
def __eq__(self, other: Series[_OrderableT]) -> Series[bool]: ... # type: ignore[overload-overlap]
207207
@overload
208208
def __eq__(self, other: object) -> Literal[False]: ...
209209
@overload
210210
def __ne__(self, other: Interval[_OrderableT]) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
211211
@overload
212-
def __ne__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ... # type: ignore[overload-overlap]
212+
def __ne__(self: IntervalT, other: IntervalIndex[IntervalT]) -> np_ndarray_bool: ...
213213
@overload
214214
def __ne__(self, other: Series[_OrderableT]) -> Series[bool]: ... # type: ignore[overload-overlap]
215215
@overload

pandas-stubs/_libs/tslibs/dtypes.pyi

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from enum import Enum
2+
from typing import cast
23

34
from .offsets import BaseOffset
45

@@ -29,16 +30,16 @@ class FreqGroup:
2930
def get_freq_group(code: int) -> int: ...
3031

3132
class Resolution(Enum):
32-
RESO_NS: int
33-
RESO_US: int
34-
RESO_MS: int
35-
RESO_SEC: int
36-
RESO_MIN: int
37-
RESO_HR: int
38-
RESO_DAY: int
39-
RESO_MTH: int
40-
RESO_QTR: int
41-
RESO_YR: int
33+
RESO_NS = cast(int, ...)
34+
RESO_US = cast(int, ...)
35+
RESO_MS = cast(int, ...)
36+
RESO_SEC = cast(int, ...)
37+
RESO_MIN = cast(int, ...)
38+
RESO_HR = cast(int, ...)
39+
RESO_DAY = cast(int, ...)
40+
RESO_MTH = cast(int, ...)
41+
RESO_QTR = cast(int, ...)
42+
RESO_YR = cast(int, ...)
4243

4344
def __lt__(self, other) -> bool: ...
4445
def __ge__(self, other) -> bool: ...

pandas-stubs/_libs/tslibs/offsets.pyi

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ from typing import (
1212
overload,
1313
)
1414

15+
from dateutil.relativedelta import weekday as WeekdayClass
1516
import numpy as np
17+
from pandas import Timestamp
1618
from pandas.core.indexes.datetimes import DatetimeIndex
1719
from typing_extensions import Self
1820

@@ -21,7 +23,7 @@ from pandas._typing import npt
2123

2224
from pandas.tseries.holiday import AbstractHolidayCalendar
2325

24-
_DatetimeT = TypeVar("_DatetimeT", bound=date)
26+
_DatetimeT = TypeVar("_DatetimeT", bound=datetime)
2527
_TimedeltaT = TypeVar("_TimedeltaT", bound=timedelta)
2628

2729
prefix_mapping: dict[str, type]
@@ -41,26 +43,32 @@ class BaseOffset:
4143
@overload
4244
def __add__(self, other: npt.NDArray[np.object_]) -> npt.NDArray[np.object_]: ...
4345
@overload
44-
def __add__(self, other: BaseOffset) -> Self: ...
46+
def __add__(self, other: _DatetimeT) -> _DatetimeT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
47+
@overload
48+
def __add__(self, other: date) -> Timestamp: ...
4549
@overload
46-
def __add__(self, other: _DatetimeT) -> _DatetimeT: ...
50+
def __add__(self, other: BaseOffset) -> Self: ...
4751
@overload
4852
def __add__(self, other: _TimedeltaT) -> _TimedeltaT: ...
4953
@overload
5054
def __radd__(self, other: npt.NDArray[np.object_]) -> npt.NDArray[np.object_]: ...
5155
@overload
52-
def __radd__(self, other: BaseOffset) -> Self: ...
56+
def __radd__(self, other: _DatetimeT) -> _DatetimeT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
57+
@overload
58+
def __radd__(self, other: date) -> Timestamp: ...
5359
@overload
54-
def __radd__(self, other: _DatetimeT) -> _DatetimeT: ...
60+
def __radd__(self, other: BaseOffset) -> Self: ...
5561
@overload
5662
def __radd__(self, other: _TimedeltaT) -> _TimedeltaT: ...
5763
def __sub__(self, other: BaseOffset) -> Self: ...
5864
@overload
5965
def __rsub__(self, other: npt.NDArray[np.object_]) -> npt.NDArray[np.object_]: ...
6066
@overload
61-
def __rsub__(self, other: BaseOffset) -> Self: ...
67+
def __rsub__(self, other: _DatetimeT) -> _DatetimeT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
6268
@overload
63-
def __rsub__(self, other: _DatetimeT) -> _DatetimeT: ...
69+
def __rsub__(self, other: date) -> Timestamp: ...
70+
@overload
71+
def __rsub__(self, other: BaseOffset) -> Self: ...
6472
@overload
6573
def __rsub__(self, other: _TimedeltaT) -> _TimedeltaT: ...
6674
def __call__(self, other): ...
@@ -257,7 +265,7 @@ class DateOffset(RelativeDeltaOffset):
257265
year: int = ...,
258266
month: int = ...,
259267
day: int = ...,
260-
weekday: int = ...,
268+
weekday: int | WeekdayClass = ...,
261269
hour: int = ...,
262270
minute: int = ...,
263271
second: int = ...,

pandas-stubs/_libs/tslibs/timedeltas.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Timedelta(timedelta):
102102
value: int
103103
def __new__(
104104
cls,
105-
value: str | int | Timedelta | timedelta | np.timedelta64 = ...,
105+
value: str | float | Timedelta | timedelta | np.timedelta64 = ...,
106106
unit: TimeDeltaUnitChoices = ...,
107107
*,
108108
days: float | np.integer | np.floating = ...,
@@ -248,7 +248,7 @@ class Timedelta(timedelta):
248248
def __rmul__(self, other: Series[float]) -> TimedeltaSeries: ...
249249
# maybe related to https://github.com/python/mypy/issues/10755
250250
@overload
251-
def __rmul__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ... # type: ignore[misc]
251+
def __rmul__(self, other: Index[int] | Index[float]) -> TimedeltaIndex: ...
252252
# Override due to more types supported than dt.timedelta
253253
# error: Signature of "__floordiv__" incompatible with supertype "timedelta"
254254
@overload # type: ignore[override]

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,18 @@ class Timestamp(datetime):
5959
def __new__(
6060
cls,
6161
ts_input: np.integer | float | str | _date | datetime | np.datetime64 = ...,
62-
# Freq is deprecated but is left in to allow code like Timestamp(2000,1,1)
63-
# Removing it would make the other arguments position only
64-
freq: int | str | BaseOffset | None = ...,
65-
tz: str | _tzinfo | int | None = ...,
66-
unit: str | int | None = ...,
6762
year: int | None = ...,
6863
month: int | None = ...,
6964
day: int | None = ...,
7065
hour: int | None = ...,
7166
minute: int | None = ...,
7267
second: int | None = ...,
7368
microsecond: int | None = ...,
74-
nanosecond: int | None = ...,
7569
tzinfo: _tzinfo | None = ...,
7670
*,
71+
nanosecond: int | None = ...,
72+
tz: str | _tzinfo | int | None = ...,
73+
unit: str | int | None = ...,
7774
fold: Literal[0, 1] | None = ...,
7875
) -> Self: ...
7976
# GH 46171
@@ -119,8 +116,6 @@ class Timestamp(datetime):
119116
def fromordinal(
120117
cls,
121118
ordinal: int,
122-
# freq produces a FutureWarning about being deprecated in a future version
123-
freq: None = ...,
124119
tz: _tzinfo | str | None = ...,
125120
) -> Self: ...
126121
@classmethod

0 commit comments

Comments
 (0)