Skip to content

Commit 3ff2c36

Browse files
committed
Merge branch 'main' into hotfix/cmp0xff/gh718-drop-tss
2 parents f736d55 + 9980c3b commit 3ff2c36

File tree

8 files changed

+60
-38
lines changed

8 files changed

+60
-38
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,9 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
17601760
@property
17611761
def index(self) -> Index: ...
17621762
@index.setter
1763-
def index(self, idx: Index) -> None: ...
1763+
def index(
1764+
self, idx: AnyArrayLike | SequenceNotStr[Hashable] | tuple[Hashable, ...]
1765+
) -> None: ...
17641766
@property
17651767
def loc(self) -> _LocIndexerFrame[Self]: ...
17661768
@property

pandas-stubs/core/series.pyi

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ from typing import (
2626
Generic,
2727
Literal,
2828
NoReturn,
29+
Protocol,
2930
final,
3031
overload,
3132
type_check_only,
3233
)
3334

35+
from _typeshed import SupportsGetItem
3436
from matplotlib.axes import (
3537
Axes as PlotAxes,
3638
SubplotBase,
@@ -186,6 +188,7 @@ from pandas._typing import (
186188
ValueKeyFunc,
187189
VoidDtypeArg,
188190
WriteBuffer,
191+
_T_co,
189192
np_1darray,
190193
np_ndarray_anyint,
191194
np_ndarray_bool,
@@ -203,6 +206,10 @@ from pandas.core.dtypes.dtypes import CategoricalDtype
203206

204207
from pandas.plotting import PlotAccessor
205208

209+
@type_check_only
210+
class _SupportsAdd(Protocol[_T_co]):
211+
def __add__(self, value: Self, /) -> _T_co: ...
212+
206213
class _iLocIndexerSeries(_iLocIndexer, Generic[S1]):
207214
# get item
208215
@overload
@@ -500,7 +507,9 @@ class Series(IndexOpsMixin[S1], NDFrame):
500507
@property
501508
def index(self) -> Index: ...
502509
@index.setter
503-
def index(self, idx: Index) -> None: ...
510+
def index(
511+
self, idx: AnyArrayLike | SequenceNotStr[Hashable] | tuple[Hashable, ...]
512+
) -> None: ...
504513
@overload
505514
def reset_index(
506515
self,
@@ -4144,34 +4153,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
41444153
numeric_only: _bool = False,
41454154
**kwargs: Any,
41464155
) -> float: ...
4147-
@overload
4148-
def sum(
4149-
self: Series[Never],
4150-
axis: AxisIndex | None = 0,
4151-
skipna: _bool | None = ...,
4152-
numeric_only: _bool = ...,
4153-
min_count: int = ...,
4154-
**kwargs: Any,
4155-
) -> Any: ...
4156-
# between `Series[bool]` and `Series[int]`.
4157-
@overload
41584156
def sum(
4159-
self: Series[bool],
4157+
self: SupportsGetItem[Scalar, _SupportsAdd[_T]],
41604158
axis: AxisIndex | None = 0,
41614159
skipna: _bool | None = ...,
41624160
numeric_only: _bool = ...,
41634161
min_count: int = ...,
41644162
**kwargs: Any,
4165-
) -> int: ...
4166-
@overload
4167-
def sum(
4168-
self: Series[S1],
4169-
axis: AxisIndex | None = 0,
4170-
skipna: _bool | None = ...,
4171-
numeric_only: _bool = ...,
4172-
min_count: int = ...,
4173-
**kwargs: Any,
4174-
) -> S1: ...
4163+
) -> _T: ...
41754164
def to_list(self) -> list[S1]: ...
41764165
@overload # type: ignore[override]
41774166
def to_numpy(

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ mypy = "1.17.1"
4040
pandas = "2.3.2"
4141
pyarrow = ">=10.0.1"
4242
pytest = ">=7.1.2"
43-
pyright = ">=1.1.404"
44-
ty = "^0.0.1a9"
43+
pyright = ">=1.1.405"
44+
ty = "^0.0.1a20"
4545
pyrefly = "^0.21.0"
4646
poethepoet = ">=0.16.5"
4747
loguru = ">=0.6.0"

scripts/test/run.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ def nightly_pandas():
9494
"pip",
9595
"install",
9696
"--pre",
97-
"--use-deprecated=legacy-resolver",
9897
"--upgrade",
9998
"--extra-index-url",
10099
"https://pypi.anaconda.org/scientific-python-nightly-wheels/simple",

tests/series/test_series.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3980,3 +3980,12 @@ def test_series_explode() -> None:
39803980

39813981
check(assert_type(s.explode(), pd.Series), pd.Series)
39823982
check(assert_type(s.explode(ignore_index=True), pd.Series), pd.Series)
3983+
3984+
3985+
def test_series_index_setter() -> None:
3986+
"""Test Series.index setter property GH1366."""
3987+
sr = pd.Series(["a", "b"])
3988+
3989+
check(assert_type(sr.index, pd.Index), pd.Index)
3990+
sr.index = [2, 3]
3991+
check(assert_type(sr.index, pd.Index), pd.Index)

tests/test_frame.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4649,7 +4649,7 @@ def test_unstack() -> None:
46494649
df_flt = pd.DataFrame(
46504650
[
46514651
["a", "b", 1],
4652-
["a", "a", 12],
4652+
["a", "a", 12.2],
46534653
["b", "b", 14],
46544654
]
46554655
).set_index([0, 1])
@@ -4812,3 +4812,12 @@ def test_from_records() -> None:
48124812
),
48134813
pd.DataFrame,
48144814
)
4815+
4816+
4817+
def test_frame_index_setter() -> None:
4818+
"""Test DataFrame.index setter property GH1366."""
4819+
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
4820+
4821+
check(assert_type(df.index, pd.Index), pd.Index)
4822+
df.index = [2, 3]
4823+
check(assert_type(df.index, pd.Index), pd.Index)

tests/test_testing.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing_extensions import assert_type
1111

1212
from tests import (
13+
PD_LTE_23,
1314
TYPE_CHECKING_INVALID_USAGE,
1415
check,
1516
ensure_clean,
@@ -20,14 +21,23 @@ def test_types_assert_series_equal() -> None:
2021
s1 = pd.Series([0, 1, 1, 0])
2122
s2 = pd.Series([0, 1, 1, 0])
2223
assert_series_equal(left=s1, right=s2)
23-
assert_series_equal(
24-
s1,
25-
s2,
26-
check_freq=False,
27-
check_categorical=True,
28-
check_flags=True,
29-
check_datetimelike_compat=True,
30-
)
24+
if PD_LTE_23:
25+
assert_series_equal(
26+
s1,
27+
s2,
28+
check_freq=False,
29+
check_categorical=True,
30+
check_flags=True,
31+
check_datetimelike_compat=True,
32+
)
33+
else:
34+
assert_series_equal(
35+
s1,
36+
s2,
37+
check_freq=False,
38+
check_categorical=True,
39+
check_flags=True,
40+
)
3141
if TYPE_CHECKING_INVALID_USAGE:
3242
assert_series_equal( # type: ignore[call-overload] # pyright: ignore[reportCallIssue]
3343
s1,

tests/test_timefuncs.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,12 @@ def test_timestamp_timedelta_series_arithmetic() -> None:
200200
check(assert_type(r4, "pd.Series[float]"), pd.Series, float)
201201
sb = pd.Series([1, 2]) == pd.Series([1, 3])
202202
check(assert_type(sb, "pd.Series[bool]"), pd.Series, np.bool_)
203-
r5 = sb * r1
204-
check(assert_type(r5, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta)
203+
204+
# https://github.com/pandas-dev/pandas/issues/62316
205+
if PD_LTE_23:
206+
r5 = sb * r1
207+
check(assert_type(r5, "pd.Series[pd.Timedelta]"), pd.Series, pd.Timedelta)
208+
205209
r6 = r1 * 4
206210
check(assert_type(r6, "TimedeltaSeries"), pd.Series, pd.Timedelta)
207211

0 commit comments

Comments
 (0)