Skip to content

Commit 5231859

Browse files
authored
Pandas stub fixes (#129)
* Add a few missing files. Update .gitignore. Make some fixes based on the tests from the pandas-stubs package (more to come).
1 parent e7def7e commit 5231859

File tree

14 files changed

+287
-60
lines changed

14 files changed

+287
-60
lines changed

.gitignore

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ bld/
3131
[Ll]og/
3232
[Ll]ogs/
3333

34+
# JetBrains
35+
.idea
36+
3437
# Visual Studio 2015/2017 cache/options directory
3538
.vs/
3639
# Uncomment if you have tasks that create the project's static files in wwwroot
3740
#wwwroot/
38-
!.vscode/settings.json
41+
.vscode
3942

4043
# Visual Studio 2017 auto generated files
4144
Generated\ Files/
@@ -351,4 +354,9 @@ MigrationBackup/
351354
.ionide/
352355

353356
# Python virtual environment
354-
.venv/
357+
.venv
358+
359+
# Build files from utils
360+
utils/stubsplit/.eggs
361+
utils/stubsplit/build
362+
utils/stubsplit/stubsplit.egg-info

doc/pandas/core/frame.pyi.ds

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,8 @@ sorted_obj : DataFrame or None
12861286
group_keys: _bool = ...,
12871287
squeeze: _bool = ...,
12881288
observed: _bool = ...,
1289-
) -> DataFrameGroupBy:
1289+
dropna: _bool = ...,
1290+
) -> DataFrameGroupBy: ...
12901291
"""Group DataFrame using a mapper or by a Series of columns.
12911292

12921293
A groupby operation involves some combination of splitting the

doc/pandas/core/series.pyi.ds

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ starting from the end of the object, just like with Python lists.
8080
3 lion mammal 80.5
8181
"""
8282
pass
83-
def to_markdown(self, buf: Optional[FilePathOrBuffer], mode: Optional[_str] = ..., **kwargs) -> None:
83+
def to_markdown(self, buf: Optional[FilePathOrBuffer], mode: Optional[_str] = ..., index: _bool = ..., storage_options: Optional[dict] = ..., **kwargs) -> None:
8484
"""Print Series in Markdown-friendly format.
8585

8686
.. versionadded:: 1.0.0
@@ -150,7 +150,8 @@ Index : 2, Value : C
150150
group_keys: _bool = ...,
151151
squeeze: _bool = ...,
152152
observed: _bool = ...,
153-
) -> SeriesGroupBy:
153+
dropna: _bool = ...
154+
) -> SeriesGroupBy: ...
154155
"""Group Series using a mapper or by a Series of columns.
155156

156157
A groupby operation involves some combination of splitting the
@@ -550,7 +551,7 @@ Returns
550551
pass
551552
def fillna(
552553
self,
553-
value: Union[S1, Dict, Series[S1], DataFrame],
554+
value: Optional[Scalar|Dict|Series[S1]|DataFrame] = ...,
554555
method: Optional[Union[_str, Literal["backfill", "bfill", "pad", "ffill"]]] = ...,
555556
axis: SeriesAxisType = ...,
556557
limit: Optional[int] = ...,

pandas/_libs/tslibs/timedeltas.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from __future__ import annotations
2+
from datetime import timedelta
23
from typing import Any, Union, Tuple, Type, Optional, Sequence
34

45
import numpy as np
56
from pandas._typing import Dtype
67

7-
class _Timedelta:
8+
class _Timedelta(timedelta):
89
def __hash__(self) -> int: ...
910
def __richcmp__(self, other, op: int) -> Any: ...
1011
def to_timedelta64(self) -> np.timedelta64: ...

pandas/_libs/tslibs/timestamps.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import annotations
2+
from datetime import datetime, timestamp
23
import sys
34
from typing import Any, Optional, Union
45

@@ -7,7 +8,7 @@ if sys.version_info >= (3, 8):
78
else:
89
from typing_extensions import Literal
910

10-
class Timestamp(datetime.datetime):
11+
class Timestamp(datetime):
1112
def __init__(
1213
self,
1314
ts_input: Any,
@@ -35,7 +36,7 @@ class Tick(SingleConstructorOffset):
3536
def delta(self) -> int: ...
3637
@property
3738
def nanos(self) -> int: ...
38-
def is_on_offset(self, dt: datetime.datetime) -> bool: ...
39+
def is_on_offset(self, dt: datetime) -> bool: ...
3940
def is_anchored(self) -> bool: ...
4041
def __eq__(self, other) -> bool: ...
4142
def __ne__(self, other) -> bool: ...
@@ -49,7 +50,7 @@ class Tick(SingleConstructorOffset):
4950
def apply(self, other) -> Any: ...
5051
def __setstate__(self, state: Mapping) -> None: ...
5152

52-
class Timestamp:
53+
class Timestamp(timestamp):
5354
@staticmethod
5455
def combine(date, time) -> Timestamp: ...
5556
@staticmethod
@@ -108,7 +109,7 @@ class Timestamp:
108109
def to_datetime64(self) -> _np.datetime64: ...
109110
def to_numpy(self) -> _np.datetime64: ...
110111
def to_period(self, freq: Optional[str] = ...) -> Any: ...
111-
def to_pydatetime(self) -> datetime.datetime: ...
112+
def to_pydatetime(self, warn: bool = ...) -> datetime: ...
112113
def toordinal(self) -> Any: ...
113114
def tz_convert(self, tz: Any) -> Timestamp: ...
114115
def tz_localize(self, tz: Any, ambiguous: Any = ..., nonexistent: Any = ...) -> Timestamp: ...

pandas/_testing.pyi

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,23 @@ def assert_numpy_array_equal(left, right, strict_nan: bool = ..., check_dtype: b
4848
def assert_extension_array_equal(
4949
left, right, check_dtype: bool = ..., check_less_precise: bool = ..., check_exact: bool = ...,
5050
) -> None: ...
51-
def assert_series_equal(left: Series, right: Series) -> None: ...
51+
def assert_series_equal(left: Series, right: Series,
52+
check_dtype: bool = ...,
53+
check_index_type: bool|str = ...,
54+
check_series_type: bool = ...,
55+
check_less_precise: bool|int = ...,
56+
check_names : bool = ...,
57+
check_exact: bool = ...,
58+
check_datetimelike_compat: bool = ...,
59+
check_categorical: bool = ...,
60+
check_category_order: bool = ...,
61+
check_freq: bool = ...,
62+
check_flags: bool = ...,
63+
rtol: float = ...,
64+
atol: float = ...,
65+
obj: str = ...,
66+
*,
67+
check_index: bool = ...) -> None: ...
5268
def assert_frame_equal(left: DataFrame, right: DataFrame, check_like: Optional[bool] = ...) -> None: ...
5369
def assert_equal(left, right, **kwargs) -> None: ...
5470
def box_expected(expected, box_cls, transpose: bool = ...): ...

pandas/core/reshape/merge.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ from pandas import DataFrame as DataFrame, Series as Series
33
from pandas._typing import Label
44
from typing import Optional, Sequence, Union
55

6-
def merge(left: Union[DataFrame, Series],
7-
right: Union[DataFrame, Series],
6+
def merge(left: DataFrame,
7+
right: DataFrame|Series,
88
how: str = ...,
99
on: Optional[Union[Label, Sequence]] = ...,
1010
left_on: Optional[Union[Label, Sequence]] = ...,

pandas/core/series.pyi

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ from pandas.core.window.rolling import Rolling, Window
1616
from pandas._typing import ArrayLike as ArrayLike, AxisType as AxisType, Dtype as Dtype, DtypeNp as DtypeNp, \
1717
FilePathOrBuffer as FilePathOrBuffer, Level as Level, MaskType as MaskType, S1 as S1, Scalar as Scalar, \
1818
SeriesAxisType as SeriesAxisType, num as num, Label
19-
from typing import Any, Callable, Dict, Generic, Hashable, Iterable, List, Optional, Sequence, Tuple, Type, Union, overload
19+
from typing import Any, Callable, Dict, Generic, Hashable, Iterable, List, Mapping, Optional, Sequence, Tuple, Type, Union, overload
2020
if sys.version_info >= (3, 8):
2121
from typing import Literal
2222
else:
@@ -162,9 +162,9 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
162162
encoding: Optional[_str] = ...,
163163
) -> _str: ...
164164
@overload
165-
def to_markdown(self, buf: Optional[FilePathOrBuffer], mode: Optional[_str] = ..., **kwargs) -> None: ...
165+
def to_markdown(self, buf: Optional[FilePathOrBuffer], mode: Optional[_str] = ..., index: _bool = ..., storage_options: Optional[dict] = ..., **kwargs) -> None: ...
166166
@overload
167-
def to_markdown(self, mode: Optional[_str] = ...,) -> _str: ...
167+
def to_markdown(self, mode: Optional[_str] = ..., index: _bool = ..., storage_options: Optional[dict] = ...) -> _str: ...
168168
def items(self) -> Iterable[Tuple[Union[int, _str], S1]]: ...
169169
def iteritems(self) -> Iterable[Tuple[Label, S1]]: ...
170170
def keys(self) -> List: ...
@@ -180,6 +180,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
180180
group_keys: _bool = ...,
181181
squeeze: _bool = ...,
182182
observed: _bool = ...,
183+
dropna: _bool = ...
183184
) -> SeriesGroupBy: ...
184185
@overload
185186
def count(self, level: None = ...) -> int: ...
@@ -203,11 +204,13 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
203204
def corr(
204205
self, other: Series[S1], method: Literal["pearson", "kendall", "spearman"] = ..., min_periods: int = ...,
205206
) -> float: ...
206-
def cov(self, other: Series[S1], min_periods: Optional[int] = ...) -> float: ...
207+
def cov(self, other: Series[S1], min_periods: Optional[int] = ..., ddof: int = ...) -> float: ...
207208
def diff(self, periods: int = ...) -> Series[S1]: ...
208209
def autocorr(self, lag: int = ...) -> float: ...
209210
@overload
210-
def dot(self, other: Union[DataFrame, Series[S1]]) -> Series[S1]: ...
211+
def dot(self, other: Series[S1]) -> Scalar: ...
212+
@overload
213+
def dot(self, other: DataFrame) -> Series[S1]: ...
211214
@overload
212215
def dot(self, other: _ListLike) -> np.ndarray: ...
213216
def __matmul__(self, other): ...
@@ -230,7 +233,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
230233
self, other: Series[S1], func: Callable, fill_value: Optional[Scalar] = ...
231234
) -> Series[S1]: ...
232235
def combine_first(self, other: Series[S1]) -> Series[S1]: ...
233-
def update(self, other: Series[S1]) -> None: ...
236+
def update(self, other: Series[S1]|Sequence[S1]|Mapping[int, S1]) -> None: ...
234237
def sort_values(
235238
self,
236239
axis: SeriesAxisType = ...,
@@ -297,6 +300,18 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
297300
fill_axis: SeriesAxisType = ...,
298301
broadcast_axis: Optional[SeriesAxisType] = ...,
299302
) -> Tuple[Series, Series]: ...
303+
@overload
304+
def rename(
305+
self,
306+
index = ...,
307+
*,
308+
inplace: Literal[True],
309+
axis: Optional[SeriesAxisType] = ...,
310+
copy: _bool = ...,
311+
level: Optional[Level] = ...,
312+
errors: _str|Literal["raise", "ignore"] = ...
313+
) -> None: ...
314+
@overload
300315
def rename(
301316
self,
302317
index = ...,
@@ -305,30 +320,43 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
305320
copy: _bool = ...,
306321
inplace: _bool = ...,
307322
level: Optional[Level] = ...,
308-
errors: Union[_str, Literal["raise", "ignore"]] = ...
323+
errors: _str|Literal["raise", "ignore"] = ...
309324
) -> Series: ...
310325
def reindex_like(
311326
self,
312327
other: Series[S1],
313-
method: Optional[Union[_str, Literal["backfill", "bfill", "pad", "ffill", "nearest"]]] = ...,
328+
method: Optional[_str|Literal["backfill", "bfill", "pad", "ffill", "nearest"]] = ...,
314329
copy: _bool = ...,
315330
limit: Optional[int] = ...,
316331
tolerance: Optional[float] = ...,
317332
) -> Series: ...
333+
@overload
318334
def drop(
319335
self,
320-
labels: Optional[Union[_str, List]] = ...,
336+
labels: Optional[_str|int|List] = ...,
321337
axis: SeriesAxisType = ...,
322-
index: Optional[Union[List[_str], List[int], Index]] = ...,
323-
columns: Optional[Union[_str, List]] = ...,
338+
index: Optional[List[_str]|List[int]|Index] = ...,
339+
columns: Optional[_str|List] = ...,
340+
level: Optional[Level] = ...,
341+
errors: Literal["ignore", "raise"] = ...,
342+
*,
343+
inplace: Literal[True]
344+
) -> None: ...
345+
@overload
346+
def drop(
347+
self,
348+
labels: Optional[_str|int|List] = ...,
349+
axis: SeriesAxisType = ...,
350+
index: Optional[List[_str]|List[int]|Index] = ...,
351+
columns: Optional[_str|List] = ...,
324352
level: Optional[Level] = ...,
325353
inplace: _bool = ...,
326354
errors: Literal["ignore", "raise"] = ...,
327355
) -> Series: ...
328356
@overload
329357
def fillna(
330358
self,
331-
value: Union[Scalar, Dict, Series[S1], DataFrame],
359+
value: Optional[Scalar|Dict|Series[S1]|DataFrame] = ...,
332360
method: Optional[Union[_str, Literal["backfill", "bfill", "pad", "ffill"]]] = ...,
333361
axis: SeriesAxisType = ...,
334362
limit: Optional[int] = ...,
@@ -339,7 +367,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
339367
@overload
340368
def fillna(
341369
self,
342-
value: Union[Scalar, Dict, Series[S1], DataFrame],
370+
value: Optional[Scalar|Dict|Series[S1]|DataFrame] = ...,
343371
method: Optional[Union[_str, Literal["backfill", "bfill", "pad", "ffill"]]] = ...,
344372
axis: SeriesAxisType = ...,
345373
*,
@@ -349,7 +377,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
349377
@overload
350378
def fillna(
351379
self,
352-
value: Union[Scalar, Dict, Series[S1], DataFrame],
380+
value: Optional[Scalar|Dict|Series[S1]|DataFrame] = ...,
353381
method: Optional[Union[_str, Literal["backfill", "bfill", "pad", "ffill"]]] = ...,
354382
axis: SeriesAxisType = ...,
355383
inplace: _bool = ...,
@@ -381,6 +409,11 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
381409
def isnull(self) -> Series[_bool]: ...
382410
def notna(self) -> Series[_bool]: ...
383411
def notnull(self) -> Series[_bool]: ...
412+
@overload
413+
def dropna(
414+
self, axis: SeriesAxisType = ..., how: Optional[_str] = ..., *, inplace: Literal[True]
415+
) -> None: ...
416+
@overload
384417
def dropna(
385418
self, axis: SeriesAxisType = ..., inplace: _bool = ..., how: Optional[_str] = ...,
386419
) -> Series[S1]: ...
@@ -453,33 +486,27 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
453486
@overload
454487
def ffill(
455488
self,
456-
value: Union[S1, Dict, Series[S1], DataFrame],
457-
axis: SeriesAxisType,
458-
inplace: Literal[True],
489+
value: Union[S1, Dict, Series[S1], DataFrame] = ...,
490+
axis: SeriesAxisType = ...,
459491
limit: Optional[int] = ...,
460492
downcast: Optional[Dict] = ...,
461-
) -> Series[S1]: ...
462-
@overload
463-
def ffill(
464-
self,
465-
value: Union[S1, Dict, Series[S1], DataFrame],
493+
*,
466494
inplace: Literal[True],
467-
limit: Optional[int] = ...,
468-
downcast: Optional[Dict] = ...,
469495
) -> None: ...
470496
@overload
471497
def ffill(
472498
self,
473-
value: Union[S1, Dict, Series[S1], DataFrame],
499+
value: Union[S1, Dict, Series[S1], DataFrame] = ...,
474500
axis: SeriesAxisType = ...,
475-
*,
476501
limit: Optional[int] = ...,
477502
downcast: Optional[Dict] = ...,
478-
) -> Series[S1]: ...
503+
*,
504+
inplace: Literal[False],
505+
) -> Series[S1]: ...
479506
@overload
480507
def ffill(
481508
self,
482-
value: Union[S1, Dict, Series[S1], DataFrame],
509+
value: Union[S1, Dict, Series[S1], DataFrame] = ...,
483510
axis: SeriesAxisType = ...,
484511
inplace: _bool = ...,
485512
limit: Optional[int] = ...,
@@ -488,7 +515,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
488515
@overload
489516
def bfill(
490517
self,
491-
value: Union[S1, Dict, Series[S1], DataFrame],
518+
value: Union[S1, Dict, Series[S1], DataFrame] = ...,
492519
axis: SeriesAxisType = ...,
493520
limit: Optional[int] = ...,
494521
downcast: Optional[Dict] = ...,
@@ -498,12 +525,13 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
498525
@overload
499526
def bfill(
500527
self,
501-
value: Union[S1, Dict, Series[S1], DataFrame],
528+
value: Union[S1, Dict, Series[S1], DataFrame] = ...,
502529
axis: SeriesAxisType = ...,
503-
*,
504530
limit: Optional[int] = ...,
505531
downcast: Optional[Dict] = ...,
506-
) -> Series[S1]: ...
532+
*,
533+
inplace: Literal[False]
534+
) -> Series[S1]: ...
507535
@overload
508536
def bfill(
509537
self,

pandas/core/strings.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,3 @@ class StringMethods(NoNewAttributesMixin, Generic[RT]):
9292
isnumeric = ...
9393
isdecimal = ...
9494

95-

pandas/core/tools/datetimes.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def to_datetime(
4141
unit: Optional[str] = ...,
4242
infer_datetime_format: bool = ...,
4343
origin: Scalar = ...,
44-
cache: bool = ...) -> datetime: ...
44+
cache: bool = ...) -> Timestamp: ...
4545
@overload
4646
def to_datetime(
4747
arg: Union[list, tuple, ArrayLike],

0 commit comments

Comments
 (0)