Skip to content

Commit 283fc23

Browse files
Merge branch 'main' of github.com:loicdiridollou/pandas-stubs into gh203_groupby
2 parents 9883723 + 1a314a0 commit 283fc23

File tree

10 files changed

+63
-46
lines changed

10 files changed

+63
-46
lines changed

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: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ from typing import (
1414

1515
from dateutil.relativedelta import weekday as WeekdayClass
1616
import numpy as np
17+
from pandas import Timestamp
1718
from pandas.core.indexes.datetimes import DatetimeIndex
1819
from typing_extensions import Self
1920

@@ -22,7 +23,7 @@ from pandas._typing import npt
2223

2324
from pandas.tseries.holiday import AbstractHolidayCalendar
2425

25-
_DatetimeT = TypeVar("_DatetimeT", bound=date)
26+
_DatetimeT = TypeVar("_DatetimeT", bound=datetime)
2627
_TimedeltaT = TypeVar("_TimedeltaT", bound=timedelta)
2728

2829
prefix_mapping: dict[str, type]
@@ -42,26 +43,32 @@ class BaseOffset:
4243
@overload
4344
def __add__(self, other: npt.NDArray[np.object_]) -> npt.NDArray[np.object_]: ...
4445
@overload
45-
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: ...
4649
@overload
47-
def __add__(self, other: _DatetimeT) -> _DatetimeT: ...
50+
def __add__(self, other: BaseOffset) -> Self: ...
4851
@overload
4952
def __add__(self, other: _TimedeltaT) -> _TimedeltaT: ...
5053
@overload
5154
def __radd__(self, other: npt.NDArray[np.object_]) -> npt.NDArray[np.object_]: ...
5255
@overload
53-
def __radd__(self, other: BaseOffset) -> Self: ...
56+
def __radd__(self, other: _DatetimeT) -> _DatetimeT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
5457
@overload
55-
def __radd__(self, other: _DatetimeT) -> _DatetimeT: ...
58+
def __radd__(self, other: date) -> Timestamp: ...
59+
@overload
60+
def __radd__(self, other: BaseOffset) -> Self: ...
5661
@overload
5762
def __radd__(self, other: _TimedeltaT) -> _TimedeltaT: ...
5863
def __sub__(self, other: BaseOffset) -> Self: ...
5964
@overload
6065
def __rsub__(self, other: npt.NDArray[np.object_]) -> npt.NDArray[np.object_]: ...
6166
@overload
62-
def __rsub__(self, other: BaseOffset) -> Self: ...
67+
def __rsub__(self, other: _DatetimeT) -> _DatetimeT: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
6368
@overload
64-
def __rsub__(self, other: _DatetimeT) -> _DatetimeT: ...
69+
def __rsub__(self, other: date) -> Timestamp: ...
70+
@overload
71+
def __rsub__(self, other: BaseOffset) -> Self: ...
6572
@overload
6673
def __rsub__(self, other: _TimedeltaT) -> _TimedeltaT: ...
6774
def __call__(self, other): ...

pandas-stubs/_version.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ version_json: str = ...
44

55
def get_versions(): ...
66

7-
_stub_version: Literal["2.2.2.240909"]
7+
_stub_version: Literal["2.2.3.241009"]

pandas-stubs/core/frame.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,9 @@ class DataFrame(NDFrame, OpsMixin):
605605
@overload
606606
def __getitem__(self, key: Scalar | tuple[Hashable, ...]) -> Series: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
607607
@overload
608-
def __getitem__(self, key: Iterable[Hashable] | slice) -> DataFrame: ...
608+
def __getitem__( # pyright: ignore[reportOverlappingOverload]
609+
self, key: Iterable[Hashable] | slice
610+
) -> DataFrame: ...
609611
@overload
610612
def __getitem__(self, key: Hashable) -> Series: ...
611613
def isetitem(

pandas-stubs/core/groupby/generic.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
238238
self, key: Scalar | Hashable | tuple[Hashable, ...]
239239
) -> SeriesGroupBy[Any, ByT]: ...
240240
@overload
241-
def __getitem__( # pyright: ignore[reportIncompatibleMethodOverride]
241+
def __getitem__( # pyright: ignore[reportIncompatibleMethodOverride, reportOverlappingOverload]
242242
self, key: Iterable[Hashable] | slice
243243
) -> DataFrameGroupBy[ByT, bool]: ...
244244
def nunique(self, dropna: bool = ...) -> DataFrame: ...

pandas-stubs/core/groupby/groupby.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class BaseGroupBy(SelectionMixin[NDFrameT], GroupByIndexingMixin):
141141
@overload
142142
def __getitem__(self: BaseGroupBy[DataFrame], key: Scalar | Hashable | tuple[Hashable, ...]) -> generic.SeriesGroupBy: ... # type: ignore[overload-overlap]
143143
@overload
144-
def __getitem__(
144+
def __getitem__( # pyright: ignore[reportOverlappingOverload]
145145
self: BaseGroupBy[DataFrame], key: Iterable[Hashable] | slice
146146
) -> generic.DataFrameGroupBy: ...
147147
@overload

pandas-stubs/core/interchange/dataframe_protocol.pyi

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,34 @@ import enum
1111
from typing import (
1212
Any,
1313
TypedDict,
14+
cast,
1415
)
1516

1617
class DlpackDeviceType(enum.IntEnum):
17-
CPU: int
18-
CUDA: int
19-
CPU_PINNED: int
20-
OPENCL: int
21-
VULKAN: int
22-
METAL: int
23-
VPI: int
24-
ROCM: int
18+
CPU = cast(int, ...)
19+
CUDA = cast(int, ...)
20+
CPU_PINNED = cast(int, ...)
21+
OPENCL = cast(int, ...)
22+
VULKAN = cast(int, ...)
23+
METAL = cast(int, ...)
24+
VPI = cast(int, ...)
25+
ROCM = cast(int, ...)
2526

2627
class DtypeKind(enum.IntEnum):
27-
INT: int
28-
UINT: int
29-
FLOAT: int
30-
BOOL: int
31-
STRING: int
32-
DATETIME: int
33-
CATEGORICAL: int
28+
INT = cast(int, ...)
29+
UINT = cast(int, ...)
30+
FLOAT = cast(int, ...)
31+
BOOL = cast(int, ...)
32+
STRING = cast(int, ...)
33+
DATETIME = cast(int, ...)
34+
CATEGORICAL = cast(int, ...)
3435

3536
class ColumnNullType(enum.IntEnum):
36-
NON_NULLABLE: int
37-
USE_NAN: int
38-
USE_SENTINEL: int
39-
USE_BITMASK: int
40-
USE_BYTEMASK: int
37+
NON_NULLABLE = cast(int, ...)
38+
USE_NAN = cast(int, ...)
39+
USE_SENTINEL = cast(int, ...)
40+
USE_BITMASK = cast(int, ...)
41+
USE_BYTEMASK = cast(int, ...)
4142

4243
class ColumnBuffers(TypedDict):
4344
data: tuple[Buffer, Any]

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pandas-stubs"
3-
version = "2.2.2.240909"
3+
version = "2.2.3.241009"
44
description = "Type annotations for pandas"
55
authors = ["The Pandas Development Team <[email protected]>"]
66
license = "BSD-3-Clause"
@@ -37,7 +37,7 @@ mypy = "1.10.1"
3737
pandas = "2.2.3"
3838
pyarrow = ">=10.0.1"
3939
pytest = ">=7.1.2"
40-
pyright = ">= 1.1.383"
40+
pyright = ">= 1.1.387"
4141
poethepoet = ">=0.16.5"
4242
loguru = ">=0.6.0"
4343
typing-extensions = ">=4.4.0"

scripts/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import sys
2+
from typing import Any
23

34
from loguru import logger
45

56
# Config the format of log message
6-
config = {
7+
config: dict[str, Any] = {
78
"handlers": [
89
{
910
"sink": sys.stderr,

tests/test_timefuncs.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,13 @@ def test_some_offsets() -> None:
664664
),
665665
pd.DatetimeIndex,
666666
)
667-
# GH 224
668-
check(assert_type(dt.date.today() - Day(), dt.date), dt.date)
667+
# GH 755
668+
check(assert_type(dt.date.today() - Day(), pd.Timestamp), pd.Timestamp)
669+
check(assert_type(dt.date.today() + Day(), pd.Timestamp), pd.Timestamp)
670+
check(assert_type(Day() + dt.date.today(), pd.Timestamp), pd.Timestamp)
671+
check(assert_type(dt.datetime.now() - Day(), dt.datetime), dt.datetime)
672+
check(assert_type(dt.datetime.now() + Day(), dt.datetime), dt.datetime)
673+
check(assert_type(Day() + dt.datetime.now(), dt.datetime), dt.datetime)
669674
# GH 235
670675
check(
671676
assert_type(

0 commit comments

Comments
 (0)