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

Commit 9ec2545

Browse files
committed
Merge branch 'master' into release
2 parents 2f6ca2e + 699f124 commit 9ec2545

File tree

10 files changed

+143
-28
lines changed

10 files changed

+143
-28
lines changed

.editorconfig

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 4
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
end_of_line = LF
11+
charset = utf-8
12+
13+
[*.py]
14+
max_line_length = 100

.github/workflows/formatting.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ jobs:
2525
python gen_pyi.py
2626
- name: Format with black
2727
run: |
28-
python -m black --check -l 100 -t py36 -S .
29-
python -m black --check -l 100 -t py36 -S --pyi --fast matplotlib-stubs/pyplot.pyi.in
28+
python -m black --check -l 100 -t py36 .
29+
python -m black --check -l 100 -t py36 --pyi --fast matplotlib-stubs/pyplot.pyi.in
3030
- name: Lint with flake8
3131
run: |
3232
flake8 *-stubs

.github/workflows/mypy_check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Install mypy
2020
run: |
2121
python -m pip install --upgrade pip
22-
pip install mypy
22+
pip install mypy==0.770
2323
pip install .
2424
- name: Check with mypy
2525
run: |

check_all.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
#!/bin/bash
22

3-
python gen_pyi.py && black -S -l 100 -t py36 . && flake8 *-stubs && python -m pytest -vv tests/ && mypy tests && echo "Check all complete!"
3+
echo "Begin check..." \
4+
&& black -l 100 -t py36 . \
5+
&& python gen_pyi.py \
6+
&& black -l 100 -t py36 --pyi --fast matplotlib-stubs/pyplot.pyi.in \
7+
&& flake8 *-stubs \
8+
&& python -m pytest -vv tests/ \
9+
&& mypy tests \
10+
&& echo "Check all complete!"

create_tag.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,44 @@ def main() -> None:
1010
assert not repo.is_dirty(), "please commit or stash all other changes"
1111
assert repo.active_branch.name == "master", "only tag versions on master"
1212

13+
# merge master into release branch
14+
git = repo.git
15+
git.checkout("release")
16+
git.merge("--no-ff", "master", "--no-edit")
17+
print("updated release branch")
18+
1319
# find out the version number
1420
tags_minor_versions = [tag.name.split(".")[-1] for tag in repo.tags]
15-
minor_versions_as_ints = [int(mv) for mv in tags_minor_versions if mv.isdigit()]
16-
latest_minor_version = max(minor_versions_as_ints)
21+
latest_minor_version = max(int(mv) for mv in tags_minor_versions if mv.isdigit())
22+
old_version = f"0.2.{latest_minor_version}"
1723
new_version = f"0.2.{latest_minor_version + 1}"
1824
print(f"new version will be: {new_version}")
1925

2026
# change version in setup.py
2127
setup_path = Path("setup.py")
2228
with setup_path.open("r") as fhandle:
23-
new_content = fhandle.read().replace("0.3.0.dev1", new_version)
29+
file_content = fhandle.read()
30+
count = 0
31+
while old_version in file_content:
32+
file_content = file_content.replace(old_version, new_version, 1)
33+
count += 1
34+
assert count == 1, "couldn't properly change the version in setup.py... aborting"
2435
with setup_path.open("w") as fhandle:
25-
fhandle.write(new_content)
36+
fhandle.write(file_content)
2637
print("modified setup.py")
2738

2839
# commit change
29-
git = repo.git
30-
branch_name = f"releases/{new_version}"
31-
print(f"commit to branch {branch_name}")
32-
git.checkout("-b", branch_name)
3340
repo.index.add(["setup.py"])
34-
repo.index.commit("Bump version")
41+
repo.index.commit(f"Bump version to {new_version}")
3542

36-
# create tag and push
43+
# # create tag and push
3744
tag_name = f"v{new_version}"
3845
repo.create_tag(tag_name)
39-
print(f"git push origin {tag_name} {branch_name}")
40-
git.push("origin", tag_name, branch_name)
46+
print(f"git push origin release {tag_name}")
47+
git.push("origin", "release", tag_name)
4148

4249
# clean up
4350
git.checkout("master")
44-
git.branch("-D", branch_name)
45-
print(f"Deleted branch {branch_name}")
4651

4752

4853
if __name__ == "__main__":

pandas-stubs/__init__.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def read_sql(
5252
def read_feather(p: Union[Path, IO]) -> DataFrame: ...
5353
def to_numeric(
5454
arg: Union[int, float, List, Tuple, _np.ndarray, Series],
55-
errors: Literal['ignore', 'raise', 'coerce'] = ...,
56-
downcast: Literal['integer', 'signed', 'unsigned', 'float'] = ...,
55+
errors: Literal["ignore", "raise", "coerce"] = ...,
56+
downcast: Literal["integer", "signed", "unsigned", "float"] = ...,
5757
) -> Union[Series, _np.ndarray]: ...
5858
def unique(values: Series) -> _np.ndarray: ...

pandas-stubs/core/frame.pyi

+30-3
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ _DType = TypeVar("_DType", bound=_np.dtype)
3737

3838
_ColSubsetType = Union[Series, DataFrame, List[_str], _str, _np.ndarray[_np.str_]]
3939

40+
_FunctionLike = Union[_str, Callable]
41+
4042
class DataFrame:
4143
def __init__(
4244
self,
43-
data: Optional[Union[_ListLike, DataFrame, Dict[_str, _np.ndarray]]] = ...,
45+
data: Optional[Union[_ListLike, DataFrame, Dict[_str, _ListLike]]] = ...,
4446
columns: Optional[_ListLike] = ...,
4547
index: Optional[_ListLike] = ...,
4648
dtype: Optional[Type[_np.dtype]] = ...,
@@ -55,6 +57,7 @@ class DataFrame:
5557
def __getitem__(
5658
self, idx: Union[Series, DataFrame, List[_str], Index[_str], _np.ndarray[_np.str_]]
5759
) -> DataFrame: ...
60+
def __getattr__(self, name: _str) -> Series: ...
5861
def __iter__(self) -> Iterator: ...
5962
def __len__(self) -> int: ...
6063
def __setitem__(self, key: Any, value: Any) -> None: ...
@@ -164,9 +167,33 @@ class DataFrame:
164167
downcast: Dict = ...,
165168
) -> None: ...
166169
@overload
167-
def groupby(self, by: List[_str]) -> DataFrameGroupBy: ...
170+
def groupby(
171+
self,
172+
by: Union[
173+
_str,
174+
Tuple[_str, ...],
175+
List[_str],
176+
List[Tuple[_str, _str]],
177+
List[Tuple[_str, _str, _str]],
178+
],
179+
level: Union[int, _str] = ...,
180+
as_index: bool = ...,
181+
sort: bool = ...,
182+
group_keys: bool = ...,
183+
squeeze: bool = ...,
184+
observed: bool = ...,
185+
) -> DataFrameGroupBy: ...
168186
@overload
169-
def groupby(self, by: _str) -> SeriesGroupBy: ...
187+
def groupby(
188+
self,
189+
by: Union[Series[_str], Dict[_str, _str], Callable],
190+
axis: _AxisType = ...,
191+
level: Union[int, _str] = ...,
192+
sort: bool = ...,
193+
group_keys: bool = ...,
194+
squeeze: bool = ...,
195+
observed: bool = ...,
196+
) -> DataFrameGroupBy: ...
170197
def head(self, n: int) -> DataFrame: ...
171198
def idxmax(self, axis: _AxisType) -> Series: ...
172199
def insert(

pandas-stubs/core/groupby/generic.pyi

+33-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,50 @@
1-
from typing import overload, List, Iterator
1+
from typing import overload, Optional, Union, List, Dict, Iterator
2+
import numpy as _np
23

34
from pandas.core.frame import DataFrame
45
from pandas.core.series import Series
6+
from ..frame import _FunctionLike
7+
8+
_str = str # needed because Series has a property called "str"...
59

610
class GroupBy: ...
711

812
class DataFrameGroupBy(GroupBy):
913
@overload
10-
def __getitem__(self, item: str) -> Series: ...
14+
def __getitem__(self, item: _str) -> SeriesGroupBy: ...
1115
@overload
12-
def __getitem__(self, item: List[str]) -> DataFrame: ...
16+
def __getitem__(self, item: List[_str]) -> DataFrameGroupBy: ...
17+
def __getattr__(self, name: _str) -> SeriesGroupBy: ...
1318
def __iter__(self) -> Iterator: ...
19+
def aggregate(
20+
self, func: Union[_FunctionLike, List[_FunctionLike], Dict[_str, _FunctionLike]],
21+
) -> DataFrame: ...
22+
agg = aggregate
23+
def count(self) -> DataFrame: ...
24+
def head(self, n: int = ...) -> DataFrame: ...
25+
def max(self) -> DataFrame: ...
26+
def mean(self) -> DataFrame: ...
27+
def median(self) -> DataFrame: ...
28+
def min(self) -> DataFrame: ...
29+
def nunique(self, dropna: bool = ...) -> DataFrame: ...
30+
def quantile(self, q: float = ..., interpolation: str = ...) -> DataFrame: ...
31+
def std(self, ddof: int = ...) -> DataFrame: ...
32+
def sum(self) -> DataFrame: ...
33+
def tail(self, n: int = ...) -> DataFrame: ...
34+
def var(self, ddof: int = ...) -> DataFrame: ...
1435

1536
class SeriesGroupBy(GroupBy):
16-
def __getitem__(self, item: str) -> Series: ...
37+
def __getitem__(self, item: _str) -> Series: ...
38+
def count(self) -> Series: ...
39+
def head(self, n: int = ...) -> Series: ...
1740
def max(self) -> Series: ...
1841
def mean(self) -> Series: ...
1942
def median(self) -> Series: ...
2043
def min(self) -> Series: ...
44+
def nunique(self, dropna: bool = ...) -> Series: ...
45+
def quantile(self, q: float = ..., interpolation: str = ...) -> Series: ...
2146
def std(self, ddof: int = ...) -> Series: ...
47+
def sum(self) -> Series: ...
48+
def tail(self, n: int = ...) -> Series: ...
49+
def unique(self) -> Series[_np.ndarray]: ...
50+
def var(self, ddof: int = ...) -> Series: ...

pandas-stubs/core/series.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ from .strings import StringMethods
2525

2626
_str = str # needed because Series has a property called "str"...
2727

28-
_DType = TypeVar("_DType", _str, bool, int, float, object)
28+
_DType = TypeVar("_DType", _str, bool, int, float, object, _np.ndarray, List)
2929
_ListLike = Union[_np.ndarray, List[_DType], Dict[_str, _np.ndarray]]
3030
# dtypes for numpy
3131
_DTypeNp = TypeVar(

tests/pandas_test.py

+33
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@ def assert_type(v: T, t: Type[T]) -> None:
2121
[[1.0, 2.0], [4.0, 5.0], [7.0, 8.0]], columns=["max_speed", "shield"],
2222
)
2323
s: pd.Series[float] = df["shield"].copy()
24+
iris = pd.DataFrame(
25+
{
26+
"sepal_length": [5.1, 4.9, 4.7, 7.0, 6.4, 6.9, 6.3, 5.8, 7.1],
27+
"sepal_width": [3.5, 3.0, 3.2, 3.2, 3.2, 3.1, 3.3, 2.7, 3.0],
28+
"petal_length": [1.4, 1.4, 1.3, 4.7, 4.5, 4.9, 6.0, 5.1, 5.9],
29+
"petal_width": [0.2, 0.2, 0.2, 1.4, 1.5, 1.5, 2.5, 1.9, 2.1],
30+
"species": [
31+
"setosa",
32+
"setosa",
33+
"setosa",
34+
"versicolor",
35+
"versicolor",
36+
"versicolor",
37+
"virginica",
38+
"virginica",
39+
"virginica",
40+
],
41+
}
42+
)
2443

2544

2645
def test_getitem() -> None:
@@ -85,3 +104,17 @@ def test_series_iloc() -> None:
85104
def test_multiindex() -> None:
86105
tuples = [("bar", "one"), ("bar", "two"), ("baz", "one")]
87106
index: pd.MultiIndex = pd.MultiIndex.from_tuples(tuples, names=["first", "second"])
107+
108+
109+
def test_iris() -> None:
110+
sepal_length = iris.groupby("species")["sepal_length"]
111+
arr: np.ndarray = sepal_length.unique()[0]
112+
assert isinstance(arr, np.ndarray)
113+
d: pd.DataFrame = iris.groupby("species", as_index=False).max()
114+
assert_type(d, pd.DataFrame)
115+
e: pd.DataFrame = iris.groupby(
116+
{"sepal_length": "length", "petal_length": "length"}, axis=1
117+
).agg(lambda x: x.mean(axis="columns"))
118+
assert_type(e, pd.DataFrame)
119+
f: pd.Series = e["length"]
120+
assert_type(f, pd.Series)

0 commit comments

Comments
 (0)