Skip to content

Commit 7c201ba

Browse files
Improvements to arguments, types with stubtest
1 parent a6755d4 commit 7c201ba

File tree

5 files changed

+72
-76
lines changed

5 files changed

+72
-76
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 42 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,21 @@ else:
308308
@overload
309309
def __getitem__(self, key: Hashable) -> Series: ...
310310

311+
AstypeArgExt: TypeAlias = (
312+
AstypeArg
313+
| Literal[
314+
"number",
315+
"datetime64",
316+
"datetime",
317+
"integer",
318+
"timedelta",
319+
"timedelta64",
320+
"datetimetz",
321+
"datetime64[ns]",
322+
]
323+
)
324+
AstypeArgExtList: TypeAlias = AstypeArgExt | list[AstypeArgExt]
325+
311326
class DataFrame(NDFrame, OpsMixin, _GetItemHack):
312327

313328
__hash__: ClassVar[None] # type: ignore[assignment] # pyright: ignore[reportIncompatibleMethodOverride]
@@ -458,6 +473,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
458473
def to_gbq(
459474
self,
460475
destination_table: str,
476+
*,
461477
project_id: str | None = ...,
462478
chunksize: int | None = ...,
463479
reauth: bool = ...,
@@ -524,6 +540,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
524540
def to_parquet(
525541
self,
526542
path: FilePath | WriteBuffer[bytes],
543+
*,
527544
engine: ParquetEngine = ...,
528545
compression: Literal["snappy", "gzip", "brotli", "lz4", "zstd"] | None = ...,
529546
index: bool | None = ...,
@@ -535,6 +552,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
535552
def to_parquet(
536553
self,
537554
path: None = ...,
555+
*,
538556
engine: ParquetEngine = ...,
539557
compression: Literal["snappy", "gzip", "brotli", "lz4", "zstd"] | None = ...,
540558
index: bool | None = ...,
@@ -564,6 +582,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
564582
def to_html(
565583
self,
566584
buf: FilePath | WriteBuffer[str],
585+
*,
567586
columns: SequenceNotStr[Hashable] | Index | Series | None = ...,
568587
col_space: ColspaceArgType | None = ...,
569588
header: _bool = ...,
@@ -611,6 +630,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
611630
def to_html(
612631
self,
613632
buf: None = ...,
633+
*,
614634
columns: Sequence[Hashable] | None = ...,
615635
col_space: ColspaceArgType | None = ...,
616636
header: _bool = ...,
@@ -746,20 +766,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
746766
def eval(
747767
self, expr: _str, *, inplace: Literal[False] = ..., **kwargs: Any
748768
) -> Scalar | np.ndarray | Self | Series: ...
749-
AstypeArgExt: TypeAlias = (
750-
AstypeArg
751-
| Literal[
752-
"number",
753-
"datetime64",
754-
"datetime",
755-
"integer",
756-
"timedelta",
757-
"timedelta64",
758-
"datetimetz",
759-
"datetime64[ns]",
760-
]
761-
)
762-
AstypeArgExtList: TypeAlias = AstypeArgExt | list[AstypeArgExt]
763769
@overload
764770
def select_dtypes(
765771
self, include: StrDtypeArg, exclude: AstypeArgExtList | None = ...
@@ -810,6 +816,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
810816
def reindex(
811817
self,
812818
labels: Axes | None = ...,
819+
*,
813820
index: Axes | None = ...,
814821
columns: Axes | None = ...,
815822
axis: Axis | None = ...,
@@ -1320,11 +1327,19 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
13201327
) -> Self: ...
13211328
@overload
13221329
def stack(
1323-
self, level: IndexLabel = ..., dropna: _bool = ..., sort: _bool = ...
1330+
self,
1331+
level: IndexLabel = ...,
1332+
dropna: _bool = ...,
1333+
sort: _bool = ...,
1334+
future_stack: Literal[False] = ...,
13241335
) -> Self | Series: ...
13251336
@overload
13261337
def stack(
1327-
self, level: IndexLabel = ..., future_stack: _bool = ...
1338+
self,
1339+
level: IndexLabel = ...,
1340+
dropna: _NoDefaultDoNotUse = ...,
1341+
sort: _NoDefaultDoNotUse = ...,
1342+
future_stack: Literal[True] = ...,
13281343
) -> Self | Series: ...
13291344
def explode(
13301345
self, column: Sequence[Hashable], ignore_index: _bool = ...
@@ -1360,9 +1375,9 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
13601375
**kwargs: Any,
13611376
) -> Self: ...
13621377
@overload
1363-
def aggregate( # pyright: ignore[reportOverlappingOverload]
1378+
def aggregate(
13641379
self,
1365-
func: AggFuncTypeBase | AggFuncTypeDictSeries,
1380+
func: AggFuncTypeBase | AggFuncTypeDictSeries = ...,
13661381
axis: Axis = ...,
13671382
**kwargs: Any,
13681383
) -> Series: ...
@@ -1628,24 +1643,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
16281643
def isin(self, values: Iterable | Series | DataFrame | dict) -> Self: ...
16291644
@property
16301645
def plot(self) -> PlotAccessor: ...
1631-
def hist(
1632-
self,
1633-
column: _str | list[_str] | None = ...,
1634-
by: _str | ListLike | None = ...,
1635-
grid: _bool = ...,
1636-
xlabelsize: float | str | None = ...,
1637-
xrot: float | None = ...,
1638-
ylabelsize: float | str | None = ...,
1639-
yrot: float | None = ...,
1640-
ax: PlotAxes | None = ...,
1641-
sharex: _bool = ...,
1642-
sharey: _bool = ...,
1643-
figsize: tuple[float, float] | None = ...,
1644-
layout: tuple[int, int] | None = ...,
1645-
bins: int | list = ...,
1646-
backend: _str | None = ...,
1647-
**kwargs: Any,
1648-
): ...
1646+
hist = ...
16491647
def boxplot(
16501648
self,
16511649
column: _str | list[_str] | None = ...,
@@ -1780,6 +1778,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
17801778
self,
17811779
start_time: _str | dt.time,
17821780
end_time: _str | dt.time,
1781+
inclusive: IntervalClosedType = ...,
17831782
axis: Axis | None = ...,
17841783
) -> Self: ...
17851784
@overload
@@ -1980,8 +1979,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
19801979
@final
19811980
def head(self, n: int = ...) -> Self: ...
19821981
@final
1983-
def infer_objects(self) -> Self: ...
1984-
# def info
1982+
def infer_objects(self, copy: _bool | None = ...) -> Self: ...
19851983
@overload
19861984
def interpolate(
19871985
self,
@@ -2077,15 +2075,13 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
20772075
self,
20782076
axis: Axis | None = ...,
20792077
skipna: _bool | None = ...,
2080-
level: None = ...,
20812078
numeric_only: _bool = ...,
20822079
**kwargs: Any,
20832080
) -> Series: ...
20842081
def min(
20852082
self,
20862083
axis: Axis | None = ...,
20872084
skipna: _bool | None = ...,
2088-
level: None = ...,
20892085
numeric_only: _bool = ...,
20902086
**kwargs: Any,
20912087
) -> Series: ...
@@ -2117,8 +2113,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
21172113
periods: int = ...,
21182114
fill_method: None = ...,
21192115
freq: DateOffset | dt.timedelta | _str | None = ...,
2120-
*,
2121-
axis: Axis = ...,
21222116
fill_value: Scalar | NAType | None = ...,
21232117
) -> Self: ...
21242118
def pop(self, item: _str) -> Series: ...
@@ -2133,7 +2127,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
21332127
self,
21342128
axis: Axis | None = ...,
21352129
skipna: _bool | None = ...,
2136-
level: None = ...,
21372130
numeric_only: _bool = ...,
21382131
min_count: int = ...,
21392132
**kwargs: Any,
@@ -2142,7 +2135,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
21422135
self,
21432136
axis: Axis | None = ...,
21442137
skipna: _bool = ...,
2145-
level: None = ...,
21462138
numeric_only: _bool = ...,
21472139
min_count: int = ...,
21482140
**kwargs: Any,
@@ -2305,18 +2297,16 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
23052297
self,
23062298
axis: Axis | None = ...,
23072299
skipna: _bool | None = ...,
2308-
level: None = ...,
23092300
ddof: int = ...,
23102301
numeric_only: _bool = ...,
23112302
**kwargs: Any,
23122303
) -> Series: ...
23132304
# Not actually positional, but used to handle removal of deprecated
2314-
def set_axis(self, labels, *, axis: Axis, copy: _bool = ...) -> Self: ...
2305+
def set_axis(self, labels, *, axis: Axis = ..., copy: _bool = ...) -> Self: ...
23152306
def skew(
23162307
self,
23172308
axis: Axis | None = ...,
23182309
skipna: _bool | None = ...,
2319-
level: None = ...,
23202310
numeric_only: _bool = ...,
23212311
**kwargs: Any,
23222312
) -> Series: ...
@@ -2326,7 +2316,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
23262316
self,
23272317
axis: Axis = ...,
23282318
skipna: _bool = ...,
2329-
level: None = ...,
23302319
ddof: int = ...,
23312320
numeric_only: _bool = ...,
23322321
**kwargs: Any,
@@ -2347,9 +2336,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
23472336
) -> Self: ...
23482337
def sum(
23492338
self,
2350-
axis: Axis | None = ...,
2339+
axis: Axis = ...,
23512340
skipna: _bool | None = ...,
2352-
level: None = ...,
23532341
numeric_only: _bool = ...,
23542342
min_count: int = ...,
23552343
**kwargs: Any,
@@ -2434,6 +2422,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
24342422
def to_string(
24352423
self,
24362424
buf: FilePath | WriteBuffer[str],
2425+
*,
24372426
columns: SequenceNotStr[Hashable] | Index | Series | None = ...,
24382427
col_space: int | list[int] | dict[HashableT, int] | None = ...,
24392428
header: _bool | list[_str] | tuple[str, ...] = ...,
@@ -2457,6 +2446,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
24572446
def to_string(
24582447
self,
24592448
buf: None = ...,
2449+
*,
2450+
level: None = ...,
24602451
columns: Sequence[Hashable] | Index | Series | None = ...,
24612452
col_space: int | list[int] | dict[Hashable, int] | None = ...,
24622453
header: _bool | Sequence[_str] = ...,
@@ -2513,9 +2504,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
25132504
) -> Self: ...
25142505
def var(
25152506
self,
2516-
axis: Axis | None = ...,
2507+
axis: Axis = ...,
25172508
skipna: _bool | None = ...,
2518-
level: None = ...,
25192509
ddof: int = ...,
25202510
numeric_only: _bool = ...,
25212511
**kwargs: Any,

pandas-stubs/core/generic.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ class NDFrame(indexing.IndexingMixin):
143143
def to_markdown(
144144
self,
145145
buf: FilePath | WriteBuffer[str],
146-
mode: FileWriteMode | None = ...,
146+
*,
147+
mode: FileWriteMode = ...,
147148
index: _bool = ...,
148149
storage_options: StorageOptions = ...,
149150
**kwargs: Any,
@@ -152,6 +153,7 @@ class NDFrame(indexing.IndexingMixin):
152153
def to_markdown(
153154
self,
154155
buf: None = ...,
156+
*,
155157
mode: FileWriteMode | None = ...,
156158
index: _bool = ...,
157159
storage_options: StorageOptions = ...,

0 commit comments

Comments
 (0)