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

Commit f08de82

Browse files
committed
Merge branch 'master' into release
2 parents 168fb9e + 78f6f22 commit f08de82

File tree

5 files changed

+100
-15
lines changed

5 files changed

+100
-15
lines changed

numpy-stubs/__init__.pyi

+19-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,9 @@ def array(object: Union[ndarray[_DType], _NestedList[ndarray[_DType]]]) -> ndarr
511511
@overload
512512
def array(object: Tuple) -> ndarray[bool_]: ...
513513
@overload
514-
def arange(stop: int, start: int = ..., step: int = ...) -> ndarray[int64]: ...
514+
def arange(start: int, stop: int = ..., step: int = ...) -> ndarray[int64]: ...
515+
@overload
516+
def arange(start: float, stop: float = ..., step: float = ...) -> ndarray[float64]: ...
515517
@overload
516518
def arange(range_: int, dtype: Type[_DType]) -> ndarray[_DType]: ...
517519
@overload
@@ -561,6 +563,12 @@ def fromiter(iterable: Iterator, dytpe: Type[_DType], count: int = ...) -> ndarr
561563
def fromstring(
562564
string: str, dtype: Type[_DType] = ..., count: int = ..., sep: str = ...
563565
) -> ndarray: ...
566+
def frombuffer(
567+
buffer: Union[bytes, bytearray, memoryview],
568+
dtype: Type[_DType] = ...,
569+
count: int = ...,
570+
offset: int = ...,
571+
) -> ndarray: ...
564572
def histogramdd(
565573
a: ndarray,
566574
bins: Optional[Union[ndarray, Series, List, int]],
@@ -730,6 +738,14 @@ def isclose(
730738
def in1d(
731739
ar1: ndarray[_DType], ar2: ndarray[_DType], assume_unique: bool = ..., inverse: bool = ...
732740
) -> ndarray[bool_]: ...
741+
def interp(
742+
x: _ArrayLike,
743+
xp: Sequence[float],
744+
fp: Sequence[Union[float, complex]],
745+
left: Optional[Union[float, complex]] = ...,
746+
right: Optional[Union[float, complex]] = ...,
747+
period: Optional[float] = ...,
748+
) -> ndarray: ...
733749
def isin(element: Sequence[_DType], test_element: _DType) -> ndarray[_DType]: ...
734750
@overload
735751
def isnan(x: float64) -> bool: ...
@@ -896,6 +912,8 @@ nancumsum = cumsum
896912
nanmean = mean
897913
nanstd = std
898914
nansum = sum
915+
nanmin = min
916+
nanmax = max
899917

900918
#
901919
# Saving methods

pandas-stubs/core/frame.pyi

+29-13
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,30 @@ class DataFrame:
5757
): ...
5858
#
5959
# magic methods
60+
def __add__(self, other: float) -> DataFrame: ...
61+
def __and__(self, other: DataFrame) -> DataFrame: ...
6062
def __eq__(self, other: Union[float, Series, DataFrame]) -> DataFrame: ... # type: ignore
61-
def __ne__(self, other: Union[float, Series, DataFrame]) -> DataFrame: ... # type: ignore
63+
def __floordiv__(self, other: float) -> DataFrame: ...
64+
def __ge__(self, other: float) -> DataFrame: ...
65+
def __getattr__(self, name: _str) -> Series: ...
6266
@overload
6367
def __getitem__(self, idx: _str) -> Series: ...
6468
@overload
6569
def __getitem__(
6670
self, idx: Union[Series, DataFrame, List[_str], Index[_str], _np.ndarray[_np.str_]]
6771
) -> DataFrame: ...
68-
def __getattr__(self, name: _str) -> Series: ...
72+
def __gt__(self, other: float) -> DataFrame: ...
6973
def __iter__(self) -> Iterator: ...
70-
def __len__(self) -> int: ...
71-
def __setitem__(self, key: Any, value: Any) -> None: ...
7274
def __le__(self, other: float) -> DataFrame: ...
75+
def __len__(self) -> int: ...
7376
def __lt__(self, other: float) -> DataFrame: ...
74-
def __ge__(self, other: float) -> DataFrame: ...
75-
def __gt__(self, other: float) -> DataFrame: ...
7677
def __mul__(self, other: float) -> DataFrame: ...
77-
def __floordiv__(self, other: float) -> DataFrame: ...
78-
def __and__(self, other: DataFrame) -> DataFrame: ...
79-
def __add__(self, other: float) -> DataFrame: ...
78+
def __ne__(self, other: Union[float, Series, DataFrame]) -> DataFrame: ... # type: ignore
8079
def __or__(self, other: DataFrame) -> DataFrame: ...
80+
def __radd__(self, other: float) -> DataFrame: ...
81+
def __rsub__(self, other: float) -> DataFrame: ...
82+
def __setitem__(self, key: Any, value: Any) -> None: ...
83+
def __sub__(self, other: float) -> DataFrame: ...
8184
#
8285
# properties
8386
@property
@@ -149,20 +152,24 @@ class DataFrame:
149152
def dropna(
150153
self,
151154
inplace: Literal[False] = ...,
152-
axis: int = ...,
155+
axis: Optional[_AxisType] = ...,
153156
how: _str = ...,
154157
subset: _ColSubsetType = ...,
155158
) -> DataFrame: ...
156159
@overload
157160
def dropna(
158-
self, inplace: Literal[True], axis: int = ..., how: _str = ..., subset: _ColSubsetType = ...
161+
self,
162+
inplace: Literal[True],
163+
axis: Optional[_AxisType] = ...,
164+
how: _str = ...,
165+
subset: _ColSubsetType = ...,
159166
) -> None: ...
160167
@overload
161168
def fillna(
162169
self,
163170
value: Union[float, Dict, Series, DataFrame, _str] = ...,
164171
method: _str = ...,
165-
axis: Union[_str, int] = ...,
172+
axis: Optional[_AxisType] = ...,
166173
inplace: Literal[False] = ...,
167174
limit: int = ...,
168175
downcast: Dict = ...,
@@ -173,7 +180,7 @@ class DataFrame:
173180
inplace: Literal[True],
174181
value: Union[float, Dict, Series, DataFrame, _str] = ...,
175182
method: _str = ...,
176-
axis: Union[_str, int] = ...,
183+
axis: Optional[_AxisType] = ...,
177184
limit: int = ...,
178185
downcast: Dict = ...,
179186
) -> None: ...
@@ -414,6 +421,15 @@ class DataFrame:
414421
def to_numpy(self) -> _np.ndarray: ...
415422
@overload
416423
def to_numpy(self, dtype: Type[_DTypeNp]) -> _np.ndarray[_DTypeNp]: ...
424+
def to_parquet(
425+
self,
426+
path: Union[Path, _str],
427+
engine: Literal["auto", "pyarrow", "fastparquet"] = ...,
428+
compression: Union[Literal["snappy", "gzip", "brotli"], None] = ...,
429+
index: Optional[bool] = ...,
430+
partition_colslist: Optional[List[_str]] = ...,
431+
**kwargs: Any,
432+
) -> None: ...
417433
def unique(self) -> DataFrame: ...
418434
def update(self, other: Union[DataFrame, Series]) -> None: ...
419435
def where(self, cond: Union[Series, DataFrame, _np.ndarray]) -> DataFrame: ...

pandas-stubs/core/series.pyi

+38-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,36 @@ class Series(Generic[_DType]):
121121
self, other: Series, method: Literal["pearson", "kendall", "spearman"] = ...
122122
) -> float: ...
123123
def count(self) -> int: ...
124-
def fillna(self, value: Union[_DType, Dict, Series, DataFrame]) -> Series: ...
124+
@overload
125+
def drop(
126+
self, labels: Union[_str, List[_str], Index], axis: _AxisType = ..., inplace: bool = ...
127+
) -> Series[_DType]: ...
128+
@overload
129+
def drop(self, *, index: Union[List[_str], Index]) -> Series[_DType]: ...
130+
@overload
131+
def drop(self, *, columns: Union[_str, List[_str], Index]) -> Series[_DType]: ...
132+
def drop_duplicates(self, keep: Union[_str, bool] = ...) -> Series[_DType]: ...
133+
def duplicated(self, keep: Literal["first", "last", False] = ...) -> Series[_DType]: ...
134+
@overload
135+
def fillna(
136+
self,
137+
value: Union[_DType, Dict, Series, DataFrame],
138+
method: _str = ...,
139+
axis: Optional[_AxisType] = ...,
140+
inplace: Literal[True] = ...,
141+
limit: int = ...,
142+
downcast: Dict = ...,
143+
) -> None: ...
144+
@overload
145+
def fillna(
146+
self,
147+
value: Union[_DType, Dict, Series, DataFrame],
148+
method: _str = ...,
149+
axis: Optional[_AxisType] = ...,
150+
inplace: Literal[False] = ...,
151+
limit: int = ...,
152+
downcast: Dict = ...,
153+
) -> Optional[Series]: ...
125154
def head(self, n: int = ...) -> Series: ...
126155
def isna(self) -> Series[bool]: ...
127156
def isnull(self) -> Series[bool]: ...
@@ -167,6 +196,13 @@ class Series(Generic[_DType]):
167196
def sort_values(
168197
self, inplace: Optional[Literal[False]] = ..., ascending: bool = ...
169198
) -> Series[_DType]: ...
199+
def shift(
200+
self,
201+
periods: int = ...,
202+
freq: Optional[_str] = ...,
203+
axis: Optional[_AxisType] = ...,
204+
fill_value: Optional[object] = ...,
205+
) -> Series[_DType]: ...
170206
def std(self) -> float: ...
171207
def sum(self) -> float: ...
172208
def to_csv(self, filename: Union[Path, _str], index: bool = ...) -> None: ...
@@ -185,6 +221,7 @@ class Series(Generic[_DType]):
185221
def tolist(self) -> List[_DType]: ...
186222
def unique(self) -> _np.ndarray: ...
187223
def update(self, other: Series) -> None: ...
224+
def where(self, cond: Union[Series, DataFrame, _np.ndarray]) -> Series[_DType]: ...
188225
def value_counts(self, normalize: bool = ...) -> Series[_DType]: ...
189226
@property
190227
def at(self) -> _AtIndexerSeries[_DType]: ...

tests/numpy_test.py

+7
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,10 @@ def test_save_load_bytes_io() -> None:
235235
f.seek(0)
236236
loaded = np.load(f)
237237
assert loaded == pytest.approx(a)
238+
239+
240+
def test_interp() -> None:
241+
assert np.interp([0.5], [0.0, 1.0], [0.0, 100.0]) == pytest.approx([50.0])
242+
assert np.interp(
243+
[1.5], [0.0, 1.0], [0.0, 100.0], left=-1.0, right=999.0, period=None
244+
) == pytest.approx([999.0])

tests/pandas_test.py

+7
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ def test_frame_replace() -> None:
277277
df.replace(r"1", 1, regex=True, inplace=True)
278278

279279

280+
# Uncomment once either pyarrow or fastparquet supports Python 3.9
281+
# def test_to_parquet(tmp_path: Path) -> None:
282+
# filename = str(tmp_path / "data.parq")
283+
# df = pd.DataFrame([[1, 2], [3, 4]], columns=["a", "b"])
284+
# df.to_parquet(filename, engine="auto", compression=None, index=True, partition_cols=["a"])
285+
286+
280287
def test_series_rank() -> None:
281288
s = pd.Series([0, 1])
282289
s.rank(method="min")

0 commit comments

Comments
 (0)