Skip to content
This repository was archived by the owner on Feb 17, 2021. It is now read-only.

Commit c7ceded

Browse files
committed
Merge branch 'master' into release
2 parents 0cff8ca + 0fb192a commit c7ceded

File tree

15 files changed

+391
-63
lines changed

15 files changed

+391
-63
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ __pycache__/
1212

1313
# generated pyi files
1414
/matplotlib-stubs/pyplot.pyi
15+
16+
# virtual environments
17+
venv
18+
19+
# vscode
20+
.vscode

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Mypy type stubs for numpy, pandas and matplotlib
22

3+
[![Join the chat at https://gitter.im/data-science-types/community](https://badges.gitter.im/data-science-types/community.svg)](https://gitter.im/data-science-types/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4+
35
This is a [PEP-561][pep-561]-compliant stub-only package
46
which provides type information for [matplotlib][matplotlib], [numpy][numpy] and [pandas][pandas].
57
The [mypy][mypy] type checker (or pytype or PyCharm) can [recognize][mypy-docs] the types in these packages by installing this package.
@@ -86,16 +88,24 @@ All pull requests are subject to CI checks.
8688
We check for compliance with Mypy and that the file formatting conforms to our Black specification.
8789

8890
You can install these dev dependencies via
89-
```
90-
pip install -e .[dev]
91+
92+
```bash
93+
pip install -e '.[dev]'
9194
```
9295

9396
This will also install numpy, pandas and matplotlib to be able to run the tests.
9497

9598
### Running CI locally (recommended)
9699

97100
We include a script that runs the CI checks that will be run when a PR is opened.
98-
To test these out locally, use the `check_all.sh` script.
101+
To test these out locally, you need to install the type stubs in your environment.
102+
Typically, you would do this with
103+
104+
```bash
105+
pip install -e .
106+
```
107+
108+
Then use the `check_all.sh` script to run all tests:
99109

100110
```bash
101111
./check_all.sh

matplotlib-stubs/pyplot.pyi.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ class Figure:
145145
label: str = ...,
146146
) -> SubplotBase: ...
147147
def legend(self, *args: Any, **kwargs: Any) -> Legend: ...
148+
def clf(self) -> None: ...
148149

149150
@overload
150151
def subplots(

numpy-stubs/__init__.pyi

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ class ndarray(Generic[_DType]):
309309
def __add__(self, value: ndarray[_DType]) -> ndarray[_DType]: ...
310310
@overload
311311
def __add__(self, value: _DType) -> ndarray[_DType]: ...
312+
@overload
313+
def __add__(self, value: float) -> ndarray[float64]: ...
312314
def __and__(self, value: object) -> ndarray[_DType]: ...
313315
@overload
314316
def __array__(self) -> ndarray[_DType]: ...
@@ -352,6 +354,8 @@ class ndarray(Generic[_DType]):
352354
def __iadd__(self, value: ndarray[_DType]) -> ndarray[_DType]: ...
353355
@overload
354356
def __iadd__(self, value: _DType) -> ndarray[_DType]: ...
357+
@overload
358+
def __iadd__(self, value: float) -> ndarray[float64]: ...
355359
def __iand__(self, value: object) -> ndarray[bool_]: ...
356360
def __ifloordiv__(self, value: object) -> None: ...
357361
def __ilshift__(self, value: object) -> None: ...
@@ -500,15 +504,22 @@ def array(object: _NestedList[float]) -> ndarray[float64]: ...
500504
@overload
501505
def array(object: _NestedList[str]) -> ndarray[str_]: ...
502506
@overload
507+
def array(object: str) -> ndarray[str_]: ...
508+
@overload
503509
def array(object: Union[ndarray[_DType], _NestedList[ndarray[_DType]]]) -> ndarray[_DType]: ...
504510
@overload
511+
def array(object: Tuple) -> ndarray[bool_]: ...
512+
@overload
505513
def arange(stop: int, start: int = ..., step: int = ...) -> ndarray[int64]: ...
506514
@overload
507515
def arange(range_: int, dtype: Type[_DType]) -> ndarray[_DType]: ...
508516
@overload
509517
def arange(range_: float) -> ndarray[float64]: ...
510518
def ascontiguousarray(a: Any, dtype: Optional[Type[_DType]] = ...) -> ndarray: ...
511519
def copy(a: Any, order: Optional[str] = ...) -> ndarray: ...
520+
def cumsum(
521+
a: ndarray[_DType], axis: Optional[int] = ..., dtype: Optional[Type[_DType]] = ...
522+
) -> ndarray[_DType]: ...
512523
def delete(
513524
arr: ndarray[_DType], object: Union[int, List[int], slice], axis: Optional[int] = ...
514525
) -> ndarray[_DType]: ...
@@ -667,7 +678,17 @@ def concatenate(arrays: Sequence[_ArrayLike[_DType]], axis: _AxesType = ...) ->
667678
def corrcoef(
668679
x: ndarray[_DType], y: Optional[ndarray[_DType]] = ..., rowvar: Optional[bool] = ...
669680
) -> ndarray[float64]: ...
681+
def cos(
682+
x: Union[_DType, ndarray[_DType], int, float, List[int], List[float]],
683+
out: Optional[Union[ndarray[_DType], Tuple[ndarray[_DType], None]]] = ...,
684+
where: Optional[_ArrayLike] = ...,
685+
) -> Union[_DType, ndarray[_DType]]: ...
670686
def cov(m: ndarray[_DType], rowvar: Optional[bool]) -> ndarray[float64]: ...
687+
def deg2rad(
688+
x: Union[_DType, ndarray[_DType], int, float, List[int], List[float]],
689+
out: Optional[Union[ndarray[_DType], Tuple[ndarray[_DType], None]]] = ...,
690+
where: Optional[_ArrayLike] = ...,
691+
) -> Union[_DType, ndarray[_DType]]: ...
671692
def diag(a: ndarray[_DType]) -> ndarray[_DType]: ...
672693
def diff(
673694
a: ndarray[_DType],
@@ -752,11 +773,6 @@ def min(a: ndarray[_DType], axis: None = ...) -> _DType: ...
752773
@overload
753774
def min(a: ndarray[_DType], axis: _AxesType, keepdims: bool = ...) -> ndarray[_DType]: ...
754775
def minimum(a: ndarray[_DType], b: ndarray[_DType]) -> ndarray[_DType]: ...
755-
@overload
756-
def nanstd(a: ndarray[_Float]) -> _Float: ...
757-
@overload
758-
def nanstd(a: ndarray[_Float], axis: _AxesType, keepdims: bool = ...) -> ndarray[_Float]: ...
759-
def nansum(a: ndarray[_DType]) -> ndarray[_DType]: ...
760776
def nan_to_num(
761777
x: ndarray[_DType],
762778
copy: bool = ...,
@@ -796,8 +812,15 @@ def searchsorted(a: ndarray[_DType], v: _DType, side: str = ...) -> int64: ...
796812
@overload
797813
def searchsorted(a: ndarray[_DType], v: ndarray[_DType], side: str = ...) -> ndarray[int64]: ...
798814
def setdiff1d(
799-
ar1: ndarray[_DType], ar2: ndarray[_DType], assume_unique: bool = ...
815+
ar1: Union[ndarray[_DType], List[_ScalarLike]],
816+
ar2: Union[ndarray[_DType], List[_ScalarLike]],
817+
assume_unique: bool = ...,
800818
) -> ndarray[_DType]: ...
819+
def sin(
820+
x: Union[_DType, ndarray[_DType], int, float, List[int], List[float]],
821+
out: Optional[Union[ndarray[_DType], Tuple[ndarray[_DType], None]]] = ...,
822+
where: Optional[_ArrayLike] = ...,
823+
) -> Union[_DType, ndarray[_DType]]: ...
801824
def sign(x: ndarray[_DType]) -> ndarray[_DType]: ...
802825
def sort(a: ndarray[_DType]) -> ndarray[_DType]: ...
803826
def split(
@@ -825,6 +848,11 @@ def take(a: ndarray[_DType], indices: ndarray[_Int], axis: _AxesType = ...) -> n
825848
def take_along_axis(
826849
arr: ndarray[_DType], indices: ndarray[_Int], axis: _AxesType = ...
827850
) -> ndarray[_DType]: ...
851+
def tan(
852+
x: Union[_DType, ndarray[_DType], int, float, List[int], List[float]],
853+
out: Optional[Union[ndarray[_DType], Tuple[ndarray[_DType], None]]] = ...,
854+
where: Optional[_ArrayLike] = ...,
855+
) -> Union[_DType, ndarray[_DType]]: ...
828856
def tile(a: ndarray[_DType], reps: Union[_NestedList[int], ndarray[_Int]]) -> ndarray[_DType]: ...
829857
def trace(a: ndarray[_DType]) -> _DType: ...
830858
def transpose(a: ndarray[_DType]) -> ndarray[_DType]: ...
@@ -857,6 +885,14 @@ def where(condition: _ConditionType, x: float, y: float) -> ndarray[float64]: ..
857885
@overload
858886
def where(condition: _ConditionType) -> Tuple[ndarray[int64], ...]: ...
859887

888+
#
889+
# nan series methods
890+
#
891+
nancumsum = cumsum
892+
nanmean = mean
893+
nanstd = std
894+
nansum = sum
895+
860896
#
861897
# Saving methods
862898
#

numpy-stubs/random.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def normal(loc: float, scale: float, size: Union[int, Tuple[int, ...]]) -> ndarr
7171
def permutation(size: int) -> ndarray[int64]: ...
7272
@overload
7373
def permutation(size: Iterable[_DType]) -> ndarray[_DType]: ...
74+
def rand(*args: int) -> ndarray[_Float]: ...
7475
def randn(*args: int) -> ndarray[_Float]: ...
7576
@overload
7677
def randint(low: int, high: int = ...) -> int64: ...

pandas-stubs/__init__.pyi

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ from typing import (
1111
Dict,
1212
Sequence,
1313
Type,
14+
TypeVar,
1415
Mapping,
1516
)
1617
from typing_extensions import Literal
@@ -30,7 +31,22 @@ def concat(
3031
) -> DataFrame: ...
3132
def cut(arr: _np.ndarray, bins: int) -> Tuple[Union[Series, _np.ndarray], _np.ndarray]: ...
3233
def get_dummies(df: Union[DataFrame, Series], columns: Optional[_ListLike] = ...) -> DataFrame: ...
33-
def isnull(df: Union[DataFrame, Series]) -> _np.ndarray: ...
34+
@overload
35+
def isna(obj: Union[float, str]) -> bool: ...
36+
@overload
37+
def isna(obj: DataFrame) -> DataFrame: ...
38+
@overload
39+
def isna(obj: Series) -> Series[bool]: ...
40+
@overload
41+
def isna(obj: Union[Index, _np.ndarray]) -> _np.ndarray[_np.bool_]: ...
42+
@overload
43+
def isnull(obj: Union[None, float, str]) -> bool: ...
44+
@overload
45+
def isnull(obj: DataFrame) -> DataFrame: ...
46+
@overload
47+
def isnull(obj: Series) -> Series[bool]: ...
48+
@overload
49+
def isnull(obj: Union[Index, _np.ndarray]) -> _np.ndarray[_np.bool_]: ...
3450
@overload
3551
def merge(left: DataFrame, right: DataFrame, on: str = ...) -> DataFrame: ...
3652
@overload

pandas-stubs/core/frame.pyi

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
1+
import sre_compile
2+
import sys
13
from pathlib import Path
24
from typing import (
35
Any,
4-
Tuple,
5-
List,
6-
Union,
76
Callable,
87
Dict,
8+
Hashable,
9+
Iterable,
10+
Iterator,
11+
List,
912
Mapping,
1013
NamedTuple,
1114
Optional,
15+
Pattern,
16+
Sequence,
17+
Tuple,
1218
Type,
13-
TypeVar,
19+
Union,
1420
overload,
15-
Iterator,
16-
Sequence,
17-
Generator,
18-
Iterable,
19-
Hashable,
2021
)
21-
from typing_extensions import Literal
22+
2223
import matplotlib
2324
import numpy as _np
25+
from typing_extensions import Literal
2426

25-
from .groupby.generic import DataFrameGroupBy, SeriesGroupBy
27+
from .groupby.generic import DataFrameGroupBy
2628
from .indexes import Index
27-
from .indexing import _iLocIndexerFrame, _LocIndexerFrame, _AtIndexerFrame
29+
from .indexing import _AtIndexerFrame, _iLocIndexerFrame, _LocIndexerFrame
2830
from .series import Series, _DTypeNp
29-
from .strings import StringMethods
3031

31-
_str = str # needed because DataFrame has a property called "str"...
32+
_str = str # needed because Series has a property called "str"...
3233

3334
_AxisType = Literal["columns", "index", 0, 1]
3435

@@ -98,8 +99,6 @@ class DataFrame:
9899
@property
99100
def size(self) -> int: ...
100101
@property
101-
def str(self) -> StringMethods: ...
102-
@property
103102
def T(self) -> DataFrame: ...
104103
# this function is deprecated:
105104
@property
@@ -123,10 +122,10 @@ class DataFrame:
123122
def append(
124123
self, s: Union[DataFrame, Dict[_str, Any]], ignore_index: bool = ..., sort: bool = ...
125124
) -> DataFrame: ...
126-
@overload
127-
def apply(self, f: Callable[..., int]) -> Series: ...
128-
@overload
129-
def apply(self, f: Callable[..., _ListLike], axis: _AxisType = ...) -> DataFrame: ...
125+
def apply(
126+
self, f: Callable[[Series], Any], axis: _AxisType = ...
127+
) -> Union[Series, DataFrame]: ...
128+
def assign(self, **kwargs: Any) -> DataFrame: ...
130129
def astype(
131130
self,
132131
dtype: Union[_TypeLike, Dict[Hashable, _TypeLike]],
@@ -137,12 +136,15 @@ class DataFrame:
137136
def corr(self, method: Optional[_str] = ..., min_periods: Optional[int] = ...) -> DataFrame: ...
138137
def count(self) -> Series: ...
139138
@overload
140-
def drop(self, labels: Union[List[_str], Index], axis: _AxisType = ...) -> DataFrame: ...
139+
def drop(
140+
self, labels: Union[_str, List[_str], Index], axis: _AxisType = ..., inplace: bool = ...
141+
) -> DataFrame: ...
141142
@overload
142143
def drop(self, *, index: Union[List[_str], Index]) -> DataFrame: ...
143144
@overload
144145
def drop(self, *, columns: Union[_str, List[_str], Index]) -> DataFrame: ...
145146
def drop_duplicates(self, keep: Union[_str, bool] = ...) -> DataFrame: ...
147+
def transpose(self, *args: int, copy: bool = ...) -> DataFrame: ...
146148
@overload
147149
def dropna(
148150
self,
@@ -176,6 +178,16 @@ class DataFrame:
176178
downcast: Dict = ...,
177179
) -> None: ...
178180
@overload
181+
def filter(
182+
self,
183+
items: List[_str],
184+
axis: _AxisType = ...,
185+
) -> DataFrame: ...
186+
@overload
187+
def filter(self, *, like: _str, axis: _AxisType = ...) -> DataFrame: ...
188+
@overload
189+
def filter(self, *, regex: _str, axis: _AxisType = ...) -> DataFrame: ...
190+
@overload
179191
def groupby(
180192
self,
181193
by: Union[
@@ -221,6 +233,23 @@ class DataFrame:
221233
def itertuples(self, index: bool = ...) -> Iterator[NamedTuple]: ...
222234
def max(self) -> Series: ...
223235
def mean(self) -> Series: ...
236+
@overload
237+
def merge(
238+
self,
239+
right: DataFrame,
240+
on: Union[_str, List[_str]],
241+
how: Literal["left", "right", "inner", "outer"] = ...,
242+
suffixes: Iterable[_str] = ...,
243+
) -> DataFrame: ...
244+
@overload
245+
def merge(
246+
self,
247+
right: DataFrame,
248+
left_on: Union[_str, List[_str]],
249+
right_on: Union[_str, List[_str]],
250+
how: Literal["left", "right", "inner", "outer"] = ...,
251+
suffixes: Iterable[_str] = ...,
252+
) -> DataFrame: ...
224253
def min(self) -> Series: ...
225254
def mode(self, axis: _AxisType = ...) -> DataFrame: ...
226255
def median(
@@ -233,14 +262,17 @@ class DataFrame:
233262
def query(self, expr: _str) -> DataFrame: ...
234263
def rank(
235264
self,
236-
axis: int,
237-
method: _str,
238-
numeric_only: Optional[bool],
239-
na_option: _str,
240-
ascending: bool,
241-
pct: bool,
265+
axis: _AxisType = ...,
266+
method: _str = ...,
267+
numeric_only: Optional[bool] = ...,
268+
na_option: _str = ...,
269+
ascending: bool = ...,
270+
pct: bool = ...,
242271
) -> DataFrame: ...
272+
@overload
243273
def reindex(self, index: Index) -> DataFrame: ...
274+
@overload
275+
def reindex(self, columns: List[_str]) -> DataFrame: ...
244276
# rename specifying mapper= and axis=
245277
@overload
246278
def rename(
@@ -261,7 +293,11 @@ class DataFrame:
261293
@overload
262294
def rename(self, *, index: _Renamer, inplace: Literal[False] = ...) -> DataFrame: ...
263295
def replace(
264-
self, a: Union[_np.dtype, _str], b: Union[_np.dtype, float, _str], regex: bool = ...
296+
self,
297+
a: Union[_np.dtype, _str, Pattern[_str]],
298+
b: Union[_np.dtype, float, _str],
299+
regex: bool = ...,
300+
inplace: bool = ...,
265301
) -> DataFrame: ...
266302
@overload
267303
def reset_index(self, drop: bool = ...) -> DataFrame: ...

0 commit comments

Comments
 (0)