Skip to content

Commit ae72ced

Browse files
Improvements to arguments, types with stubtest (#1294)
* Improvements to arguments, types with stubtest * More changes for hist * More improvements in the indexes * GH1294 PR feedback * GH1294 Fix formatting and tests * Update pandas-stubs/core/frame.pyi Co-authored-by: Irv Lustig <[email protected]> * Fix order --------- Co-authored-by: Irv Lustig <[email protected]>
1 parent bf1221e commit ae72ced

File tree

15 files changed

+95
-103
lines changed

15 files changed

+95
-103
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 46 additions & 48 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,27 +766,13 @@ 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(
765-
self, include: StrDtypeArg, exclude: AstypeArgExtList | None = ...
771+
self, include: StrDtypeArg, exclude: _AstypeArgExtList | None = ...
766772
) -> Never: ...
767773
@overload
768774
def select_dtypes(
769-
self, include: AstypeArgExtList | None, exclude: StrDtypeArg
775+
self, include: _AstypeArgExtList | None, exclude: StrDtypeArg
770776
) -> Never: ...
771777
@overload
772778
def select_dtypes(self, exclude: StrDtypeArg) -> Never: ...
@@ -775,19 +781,19 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
775781
@overload
776782
def select_dtypes(
777783
self,
778-
include: AstypeArgExtList,
779-
exclude: AstypeArgExtList | None = ...,
784+
include: _AstypeArgExtList,
785+
exclude: _AstypeArgExtList | None = ...,
780786
) -> Self: ...
781787
@overload
782788
def select_dtypes(
783789
self,
784-
include: AstypeArgExtList | None,
785-
exclude: AstypeArgExtList,
790+
include: _AstypeArgExtList | None,
791+
exclude: _AstypeArgExtList,
786792
) -> Self: ...
787793
@overload
788794
def select_dtypes(
789795
self,
790-
exclude: AstypeArgExtList,
796+
exclude: _AstypeArgExtList,
791797
) -> Self: ...
792798
def insert(
793799
self,
@@ -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 = ...,
@@ -1301,8 +1308,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
13011308
def pivot(
13021309
self,
13031310
*,
1311+
columns: IndexLabel,
13041312
index: IndexLabel = ...,
1305-
columns: IndexLabel = ...,
13061313
values: IndexLabel = ...,
13071314
) -> Self: ...
13081315
def pivot_table(
@@ -1320,11 +1327,18 @@ 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+
*,
1333+
future_stack: Literal[True],
13241334
) -> Self | Series: ...
13251335
@overload
13261336
def stack(
1327-
self, level: IndexLabel = ..., future_stack: _bool = ...
1337+
self,
1338+
level: IndexLabel = ...,
1339+
dropna: _bool = ...,
1340+
sort: _bool = ...,
1341+
future_stack: Literal[False] = ...,
13281342
) -> Self | Series: ...
13291343
def explode(
13301344
self, column: Sequence[Hashable], ignore_index: _bool = ...
@@ -1576,14 +1590,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
15761590
method: Literal["pearson", "kendall", "spearman"] = ...,
15771591
numeric_only: _bool = ...,
15781592
) -> Series: ...
1579-
@overload
1580-
def count(
1581-
self, axis: Axis = ..., numeric_only: _bool = ..., *, level: Level
1582-
) -> Self: ...
1583-
@overload
1584-
def count(
1585-
self, axis: Axis = ..., level: None = ..., numeric_only: _bool = ...
1586-
) -> Series: ...
1593+
def count(self, axis: Axis = ..., numeric_only: _bool = ...) -> Series[int]: ...
15871594
def nunique(self, axis: Axis = ..., dropna: bool = ...) -> Series: ...
15881595
def idxmax(
15891596
self, axis: Axis = ..., skipna: _bool = ..., numeric_only: _bool = ...
@@ -1780,6 +1787,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
17801787
self,
17811788
start_time: _str | dt.time,
17821789
end_time: _str | dt.time,
1790+
inclusive: IntervalClosedType = ...,
17831791
axis: Axis | None = ...,
17841792
) -> Self: ...
17851793
@overload
@@ -1980,8 +1988,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
19801988
@final
19811989
def head(self, n: int = ...) -> Self: ...
19821990
@final
1983-
def infer_objects(self) -> Self: ...
1984-
# def info
1991+
def infer_objects(self, copy: _bool | None = ...) -> Self: ...
19851992
@overload
19861993
def interpolate(
19871994
self,
@@ -2077,15 +2084,13 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
20772084
self,
20782085
axis: Axis | None = ...,
20792086
skipna: _bool | None = ...,
2080-
level: None = ...,
20812087
numeric_only: _bool = ...,
20822088
**kwargs: Any,
20832089
) -> Series: ...
20842090
def min(
20852091
self,
20862092
axis: Axis | None = ...,
20872093
skipna: _bool | None = ...,
2088-
level: None = ...,
20892094
numeric_only: _bool = ...,
20902095
**kwargs: Any,
20912096
) -> Series: ...
@@ -2117,8 +2122,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
21172122
periods: int = ...,
21182123
fill_method: None = ...,
21192124
freq: DateOffset | dt.timedelta | _str | None = ...,
2120-
*,
2121-
axis: Axis = ...,
21222125
fill_value: Scalar | NAType | None = ...,
21232126
) -> Self: ...
21242127
def pop(self, item: _str) -> Series: ...
@@ -2133,7 +2136,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
21332136
self,
21342137
axis: Axis | None = ...,
21352138
skipna: _bool | None = ...,
2136-
level: None = ...,
21372139
numeric_only: _bool = ...,
21382140
min_count: int = ...,
21392141
**kwargs: Any,
@@ -2142,7 +2144,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
21422144
self,
21432145
axis: Axis | None = ...,
21442146
skipna: _bool = ...,
2145-
level: None = ...,
21462147
numeric_only: _bool = ...,
21472148
min_count: int = ...,
21482149
**kwargs: Any,
@@ -2305,18 +2306,16 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
23052306
self,
23062307
axis: Axis | None = ...,
23072308
skipna: _bool | None = ...,
2308-
level: None = ...,
23092309
ddof: int = ...,
23102310
numeric_only: _bool = ...,
23112311
**kwargs: Any,
23122312
) -> Series: ...
23132313
# Not actually positional, but used to handle removal of deprecated
2314-
def set_axis(self, labels, *, axis: Axis, copy: _bool = ...) -> Self: ...
2314+
def set_axis(self, labels, *, axis: Axis = ..., copy: _bool = ...) -> Self: ...
23152315
def skew(
23162316
self,
23172317
axis: Axis | None = ...,
23182318
skipna: _bool | None = ...,
2319-
level: None = ...,
23202319
numeric_only: _bool = ...,
23212320
**kwargs: Any,
23222321
) -> Series: ...
@@ -2326,7 +2325,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
23262325
self,
23272326
axis: Axis = ...,
23282327
skipna: _bool = ...,
2329-
level: None = ...,
23302328
ddof: int = ...,
23312329
numeric_only: _bool = ...,
23322330
**kwargs: Any,
@@ -2347,9 +2345,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
23472345
) -> Self: ...
23482346
def sum(
23492347
self,
2350-
axis: Axis | None = ...,
2348+
axis: Axis = ...,
23512349
skipna: _bool | None = ...,
2352-
level: None = ...,
23532350
numeric_only: _bool = ...,
23542351
min_count: int = ...,
23552352
**kwargs: Any,
@@ -2434,6 +2431,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
24342431
def to_string(
24352432
self,
24362433
buf: FilePath | WriteBuffer[str],
2434+
*,
24372435
columns: SequenceNotStr[Hashable] | Index | Series | None = ...,
24382436
col_space: int | list[int] | dict[HashableT, int] | None = ...,
24392437
header: _bool | list[_str] | tuple[str, ...] = ...,
@@ -2457,6 +2455,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
24572455
def to_string(
24582456
self,
24592457
buf: None = ...,
2458+
*,
24602459
columns: Sequence[Hashable] | Index | Series | None = ...,
24612460
col_space: int | list[int] | dict[Hashable, int] | None = ...,
24622461
header: _bool | Sequence[_str] = ...,
@@ -2513,9 +2512,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
25132512
) -> Self: ...
25142513
def var(
25152514
self,
2516-
axis: Axis | None = ...,
2515+
axis: Axis = ...,
25172516
skipna: _bool | None = ...,
2518-
level: None = ...,
25192517
ddof: int = ...,
25202518
numeric_only: _bool = ...,
25212519
**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 = ...,

pandas-stubs/core/indexes/accessors.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ class _DatetimeOtherOps(Generic[_DTOtherOpsDateReturnType, _DTOtherOpsTimeReturn
140140
@property
141141
def timetz(self) -> _DTOtherOpsTimeReturnType: ...
142142

143-
class DatetimeAndPeriodProperties(_DatetimeFieldOps[Series[int]]): ...
144143
class _DatetimeLikeOps(
145144
_DatetimeFieldOps[_DTFieldOpsReturnType],
146145
_DatetimeObjectOps[_DTFreqReturnType],

pandas-stubs/core/indexes/base.pyi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ class Index(IndexOpsMixin[S1]):
280280
@final
281281
def is_(self, other) -> bool: ...
282282
def __len__(self) -> int: ...
283-
def __array__(self, dtype=...) -> np.ndarray: ...
283+
def __array__(
284+
self, dtype: _str | np.dtype = ..., copy: bool | None = ...
285+
) -> np.ndarray: ...
284286
def __array_wrap__(self, result, context=...): ...
285287
@property
286288
def dtype(self) -> DtypeObj: ...
@@ -313,9 +315,9 @@ class Index(IndexOpsMixin[S1]):
313315
def names(self, names: Sequence[Hashable]) -> None: ...
314316
def set_names(self, names, *, level=..., inplace: bool = ...): ...
315317
@overload
316-
def rename(self, name, inplace: Literal[False] = False) -> Self: ...
318+
def rename(self, name, *, inplace: Literal[False] = False) -> Self: ...
317319
@overload
318-
def rename(self, name, inplace: Literal[True]) -> None: ...
320+
def rename(self, name, *, inplace: Literal[True]) -> None: ...
319321
@property
320322
def nlevels(self) -> int: ...
321323
def get_level_values(self, level: int | _str) -> Index: ...

pandas-stubs/core/indexes/category.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class CategoricalIndex(ExtensionIndex[S1], accessor.PandasDelegate):
4040
self, dtype: DtypeArg = ..., copy: bool | None = ...
4141
) -> np.ndarray: ...
4242
def astype(self, dtype: DtypeArg, copy: bool = ...) -> Index: ...
43-
def fillna(self, value=...): ...
4443
@property
4544
def is_unique(self) -> bool: ...
4645
@property

pandas-stubs/core/indexes/datetimes.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class DatetimeIndex(DatetimeTimedeltaMixin[Timestamp], DatetimeIndexProperties):
5555
copy: bool = ...,
5656
name: Hashable = ...,
5757
) -> None: ...
58-
def __array__(self, dtype=...) -> np.ndarray: ...
5958
def __reduce__(self): ...
6059
# various ignores needed for mypy, as we do want to restrict what can be used in
6160
# arithmetic for these types

pandas-stubs/core/indexes/interval.pyi

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,7 @@ class IntervalIndex(ExtensionIndex[IntervalT], IntervalMixin):
221221
def memory_usage(self, deep: bool = ...) -> int: ...
222222
@property
223223
def is_overlapping(self) -> bool: ...
224-
# Note: tolerance no effect. It is included in all get_loc so
225-
# that signatures are consistent with base even though it is usually not used
226-
def get_loc(
227-
self,
228-
key: Label,
229-
method: FillnaOptions | Literal["nearest"] | None = ...,
230-
tolerance=...,
231-
) -> int | slice | npt.NDArray[np.bool_]: ...
224+
def get_loc(self, key: Label) -> int | slice | npt.NDArray[np.bool_]: ...
232225
@final
233226
def get_indexer(
234227
self,

0 commit comments

Comments
 (0)