Skip to content

Commit 7ab7570

Browse files
authored
Merge branch 'main' into type-transpose
2 parents 7572894 + cf79529 commit 7ab7570

File tree

9 files changed

+37
-41
lines changed

9 files changed

+37
-41
lines changed

.github/workflows/comment_commands.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ jobs:
3636
})
3737
core.setOutput('sha', pr.data.head.sha)
3838
core.setOutput('branch', pr.data.head.ref)
39+
core.setOutput('repository', pr.data.head.repo.full_name)
3940
4041
- name: Checkout code on the correct branch
4142
uses: actions/checkout@v4
4243
with:
4344
# context is not aware which branch to checkout so it would otherwise
44-
# default to main
45+
# default to main (we also need repo name to source from the right user
46+
# otherwise it will look for the branch in pandas-stubs repo)
4547
ref: ${{ steps.get-branch-info.outputs.branch }}
48+
repository: ${{ steps.get-branch-info.outputs.repository }}
4649

4750
- name: Install project dependencies
4851
uses: ./.github/setup

pandas-stubs/core/frame.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
720720
def insert(
721721
self,
722722
loc: int,
723-
column,
723+
column: Hashable,
724724
value: Scalar | ListLikeU | None,
725725
allow_duplicates: _bool = ...,
726726
) -> None: ...
@@ -1025,7 +1025,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
10251025
self,
10261026
other: DataFrame,
10271027
func: Callable,
1028-
fill_value=...,
1028+
fill_value: Scalar | None = ...,
10291029
overwrite: _bool = ...,
10301030
) -> Self: ...
10311031
def combine_first(self, other: DataFrame) -> Self: ...

pandas-stubs/core/groupby/generic.pyi

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ from collections.abc import (
33
Hashable,
44
Iterable,
55
Iterator,
6-
Mapping,
76
Sequence,
87
)
98
from typing import (
@@ -29,14 +28,11 @@ from typing_extensions import (
2928
TypeAlias,
3029
)
3130

32-
from pandas._libs.lib import NoDefault
3331
from pandas._libs.tslibs.timestamps import Timestamp
3432
from pandas._typing import (
3533
S1,
3634
AggFuncTypeBase,
3735
AggFuncTypeFrame,
38-
ArrayLike,
39-
Axis,
4036
ByT,
4137
CorrelationMethod,
4238
Dtype,
@@ -113,26 +109,13 @@ class SeriesGroupBy(GroupBy[Series[S1]], Generic[S1, ByT]):
113109
bins: int | Sequence[int] | None = ...,
114110
dropna: bool = ...,
115111
) -> Series[float]: ...
116-
def fillna(
117-
self,
118-
value: (
119-
Scalar | ArrayLike | Series | DataFrame | Mapping[Hashable, Scalar] | None
120-
) = ...,
121-
method: Literal["bfill", "ffill"] | None = ...,
122-
axis: Axis | None | NoDefault = ...,
123-
inplace: bool = ...,
124-
limit: int | None = ...,
125-
downcast: dict | None | NoDefault = ...,
126-
) -> Series[S1] | None: ...
127112
def take(
128113
self,
129114
indices: TakeIndexer,
130-
axis: Axis | NoDefault = ...,
131115
**kwargs,
132116
) -> Series[S1]: ...
133117
def skew(
134118
self,
135-
axis: Axis | NoDefault = ...,
136119
skipna: bool = ...,
137120
numeric_only: bool = ...,
138121
**kwargs,
@@ -145,8 +128,8 @@ class SeriesGroupBy(GroupBy[Series[S1]], Generic[S1, ByT]):
145128
def nsmallest(
146129
self, n: int = ..., keep: Literal["first", "last", "all"] = ...
147130
) -> Series[S1]: ...
148-
def idxmin(self, axis: Axis | NoDefault = ..., skipna: bool = ...) -> Series: ...
149-
def idxmax(self, axis: Axis | NoDefault = ..., skipna: bool = ...) -> Series: ...
131+
def idxmin(self, skipna: bool = ...) -> Series: ...
132+
def idxmax(self, skipna: bool = ...) -> Series: ...
150133
def corr(
151134
self,
152135
other: Series,
@@ -242,13 +225,11 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
242225
def nunique(self, dropna: bool = ...) -> DataFrame: ...
243226
def idxmax(
244227
self,
245-
axis: Axis | None | NoDefault = ...,
246228
skipna: bool = ...,
247229
numeric_only: bool = ...,
248230
) -> DataFrame: ...
249231
def idxmin(
250232
self,
251-
axis: Axis | None | NoDefault = ...,
252233
skipna: bool = ...,
253234
numeric_only: bool = ...,
254235
) -> DataFrame: ...
@@ -336,13 +317,10 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
336317
ascending: bool = ...,
337318
dropna: bool = ...,
338319
) -> DataFrame: ...
339-
def take(
340-
self, indices: TakeIndexer, axis: Axis | None | NoDefault = ..., **kwargs
341-
) -> DataFrame: ...
320+
def take(self, indices: TakeIndexer, **kwargs) -> DataFrame: ...
342321
@overload
343322
def skew(
344323
self,
345-
axis: Axis | None | NoDefault = ...,
346324
skipna: bool = ...,
347325
numeric_only: bool = ...,
348326
*,
@@ -352,7 +330,6 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
352330
@overload
353331
def skew(
354332
self,
355-
axis: Axis | None | NoDefault = ...,
356333
skipna: bool = ...,
357334
numeric_only: bool = ...,
358335
*,
@@ -394,14 +371,6 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]):
394371
) -> Series: ... # Series[Axes] but this is not allowed
395372
@property
396373
def dtypes(self) -> Series: ...
397-
def corrwith(
398-
self,
399-
other: DataFrame | Series,
400-
axis: Axis | NoDefault = ...,
401-
drop: bool = ...,
402-
method: CorrelationMethod = ...,
403-
numeric_only: bool = ...,
404-
) -> DataFrame: ...
405374
def __getattr__(self, name: str) -> SeriesGroupBy[Any, ByT]: ...
406375
# Overrides that provide more precise return types over the GroupBy class
407376
@final # type: ignore[misc]

pandas-stubs/core/indexes/base.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Index(IndexOpsMixin[S1]):
6767
__hash__: ClassVar[None] # type: ignore[assignment]
6868
# overloads with additional dtypes
6969
@overload
70-
def __new__(
70+
def __new__( # pyright: ignore[reportOverlappingOverload]
7171
cls,
7272
data: Sequence[int | np.integer] | IndexOpsMixin[int] | np_ndarray_anyint,
7373
*,

pandas-stubs/core/series.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
249249
copy: bool = ...,
250250
) -> Series[float]: ...
251251
@overload
252-
def __new__( # type: ignore[overload-overlap]
252+
def __new__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
253253
cls,
254254
data: Sequence[Never],
255255
index: Axes | None = ...,

pandas-stubs/io/formats/style.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ from typing import (
1111

1212
from matplotlib.colors import Colormap
1313
import numpy as np
14+
from pandas import Index
1415
from pandas.core.frame import DataFrame
1516
from pandas.core.series import Series
1617

@@ -52,6 +53,10 @@ class _DataFrameFunc(Protocol):
5253
) -> npt.NDArray | DataFrame: ...
5354

5455
class Styler(StylerRenderer):
56+
@property
57+
def columns(self) -> Index[Any]: ...
58+
@property
59+
def index(self) -> Index[Any]: ...
5560
def __init__(
5661
self,
5762
data: DataFrame | Series,

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ types-pytz = ">= 2022.1.1"
3434
numpy = ">= 1.23.5"
3535

3636
[tool.poetry.group.dev.dependencies]
37-
mypy = "1.14.1"
37+
mypy = "1.15.0"
3838
pandas = "2.2.3"
3939
pyarrow = ">=10.0.1"
4040
pytest = ">=7.1.2"
41-
pyright = ">= 1.1.393"
41+
pyright = ">=1.1.396"
4242
poethepoet = ">=0.16.5"
4343
loguru = ">=0.6.0"
4444
typing-extensions = ">=4.4.0"

tests/test_frame.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4007,3 +4007,15 @@ def test_transpose() -> None:
40074007
check(assert_type(df.transpose(), pd.DataFrame), pd.DataFrame)
40084008
check(assert_type(df.transpose(None), pd.DataFrame), pd.DataFrame)
40094009
check(assert_type(df.transpose(copy=True), pd.DataFrame), pd.DataFrame)
4010+
4011+
4012+
def test_combine() -> None:
4013+
df1 = pd.DataFrame({"A": [0, 0], "B": [4, 4]})
4014+
df2 = pd.DataFrame({"A": [1, 1], "B": [3, 3]})
4015+
take_smaller = lambda s1, s2: s1 if s1.sum() < s2.sum() else s2
4016+
assert_type(
4017+
check(
4018+
df1.combine(df2, take_smaller, fill_value=0, overwrite=False), pd.DataFrame
4019+
),
4020+
pd.DataFrame,
4021+
)

tests/test_styler.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import numpy.typing as npt
1414
from pandas import (
1515
DataFrame,
16+
Index,
1617
Series,
1718
)
1819
from pandas._testing import ensure_clean
@@ -224,3 +225,9 @@ def test_subset() -> None:
224225
check(assert_type(DF.style.highlight_min(subset=IndexSlice[1:2]), Styler), Styler)
225226
check(assert_type(DF.style.highlight_min(subset=[1]), Styler), Styler)
226227
check(assert_type(DF.style.highlight_min(subset=DF.columns[1:]), Styler), Styler)
228+
229+
230+
def test_styler_columns_and_index() -> None:
231+
styler = DF.style
232+
check(assert_type(styler.columns, Index), Index)
233+
check(assert_type(styler.index, Index), Index)

0 commit comments

Comments
 (0)