Skip to content

Commit 48cdc77

Browse files
committed
MAINT: Fix small typing issues
1 parent 68ef1c2 commit 48cdc77

File tree

6 files changed

+17
-28
lines changed

6 files changed

+17
-28
lines changed

pandas-stubs/core/arrays/sparse/array.pyi

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import numpy as np
2-
from pandas.core.arrays import (
3-
ExtensionArray,
4-
ExtensionOpsMixin,
5-
)
2+
from pandas.core.arraylike import OpsMixin
3+
from pandas.core.arrays import ExtensionArray
64
from pandas.core.base import PandasObject as PandasObject
75

8-
class SparseArray(PandasObject, ExtensionArray, ExtensionOpsMixin):
6+
class SparseArray(OpsMixin, PandasObject, ExtensionArray):
97
def __init__(
108
self,
119
data,
@@ -43,7 +41,9 @@ class SparseArray(PandasObject, ExtensionArray, ExtensionOpsMixin):
4341
def shift(self, periods: int = ..., fill_value=...): ...
4442
def unique(self): ...
4543
# Not actually positional-only, used to handle deprecations in 1.5.0
46-
def factorize(self, *, use_na_sentinal: bool = ...): ...
44+
def factorize(
45+
self, *, use_na_sentinal: bool = ...
46+
) -> tuple[np.ndarray, SparseArray]: ...
4747
def value_counts(self, dropna: bool = ...): ...
4848
def __getitem__(self, key): ...
4949
def take(self, indices, allow_fill: bool = ..., fill_value=...): ...

pandas-stubs/core/frame.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ class DataFrame(NDFrame, OpsMixin):
990990
) -> None: ...
991991
def groupby(
992992
self,
993-
by: GroupByObjectNonScalar | None = ...,
993+
by: Scalar | GroupByObjectNonScalar | None = ...,
994994
axis: AxisType = ...,
995995
level: Level | None = ...,
996996
as_index: _bool = ...,
@@ -1811,7 +1811,7 @@ class DataFrame(NDFrame, OpsMixin):
18111811
**kwargs,
18121812
) -> Series: ...
18131813
# Not actually positional, but used to handle removal of deprecated
1814-
def set_axis(self, labels, *, axis: AxisType, copy: bool = ...) -> DataFrame: ...
1814+
def set_axis(self, labels, *, axis: AxisType, copy: _bool = ...) -> DataFrame: ...
18151815
def skew(
18161816
self,
18171817
axis: AxisType | None = ...,

pandas-stubs/core/groupby/generic.pyi

+5-5
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ class SeriesGroupBy(GroupBy, Generic[S1]):
105105
engine_kwargs=...,
106106
) -> Series[S1]: ...
107107
def prod(self, numeric_only: bool = ..., min_count: int = ...) -> Series[S1]: ...
108-
def sem(self, ddof: int = ...) -> Series[float]: ...
109-
def std(self, ddof: int = ...) -> Series[float]: ...
110-
def var(self, ddof: int = ...) -> Series[float]: ...
108+
def sem(self, ddof: int = ..., numeric_only: bool = ...) -> Series[float]: ...
109+
def std(self, ddof: int = ..., numeric_only: bool = ...) -> Series[float]: ...
110+
def var(self, ddof: int = ..., numeric_only: bool = ...) -> Series[float]: ...
111111
def tail(self, n: int = ...) -> Series[S1]: ...
112112
def unique(self) -> Series: ...
113113
def hist(
@@ -308,7 +308,7 @@ class DataFrameGroupBy(GroupBy):
308308
numeric_only: bool = ...,
309309
**kwargs,
310310
) -> Series: ...
311-
def std(self, ddof: int = ...) -> DataFrame: ...
311+
def std(self, ddof: int = ..., numeric_only: bool = ...) -> DataFrame: ...
312312
def sum(
313313
self,
314314
numeric_only: bool = ...,
@@ -319,7 +319,7 @@ class DataFrameGroupBy(GroupBy):
319319
def tail(self, n: int = ...) -> DataFrame: ...
320320
def take(self, indices: Sequence, axis: AxisType = ..., **kwargs) -> DataFrame: ...
321321
def tshift(self, periods: int, freq=..., axis: AxisType = ...) -> DataFrame: ...
322-
def var(self, ddof: int = ...) -> DataFrame: ...
322+
def var(self, ddof: int = ..., numeric_only: bool = ...) -> DataFrame: ...
323323
@overload
324324
def value_counts(
325325
self,

pandas-stubs/core/series.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
400400
def to_frame(self, name: object | None = ...) -> DataFrame: ...
401401
def groupby(
402402
self,
403-
by: GroupByObjectNonScalar = ...,
403+
by: Scalar | GroupByObjectNonScalar = ...,
404404
axis: SeriesAxisType = ...,
405405
level: Level | None = ...,
406406
as_index: _bool = ...,

pandas-stubs/io/stata.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def read_stata(
5050
preserve_dtypes: bool,
5151
columns: list[HashableT] | None,
5252
order_categoricals: bool,
53-
chunksize: int | None,
54-
iterator: Literal[True],
53+
chunksize: int,
54+
iterator: bool = ...,
5555
compression: CompressionOptions = ...,
5656
storage_options: StorageOptions = ...,
5757
) -> StataReader: ...
@@ -66,7 +66,7 @@ def read_stata(
6666
preserve_dtypes: bool = ...,
6767
columns: list[HashableT] | None = ...,
6868
order_categoricals: bool = ...,
69-
chunksize: int | None = ...,
69+
chunksize: None = ...,
7070
iterator: Literal[False] = ...,
7171
compression: CompressionOptions = ...,
7272
storage_options: StorageOptions = ...,

tests/test_frame.py

-11
Original file line numberDiff line numberDiff line change
@@ -1559,21 +1559,10 @@ def test_groupby_result() -> None:
15591559
check(assert_type(index, Tuple), tuple, np.int64)
15601560
check(assert_type(value, pd.DataFrame), pd.DataFrame)
15611561

1562-
iterator2 = df.groupby("a").__iter__()
1563-
assert_type(iterator2, Iterator[Tuple[Scalar, pd.DataFrame]])
1564-
index2, value2 = next(iterator2)
1565-
assert_type((index2, value2), Tuple[Scalar, pd.DataFrame])
1566-
1567-
check(assert_type(index2, Scalar), int)
1568-
check(assert_type(value2, pd.DataFrame), pd.DataFrame)
1569-
15701562
# Want to make sure these cases are differentiated
15711563
for (k1, k2), g in df.groupby(["a", "b"]):
15721564
pass
15731565

1574-
for kk, g in df.groupby("a"):
1575-
pass
1576-
15771566

15781567
def test_setitem_list():
15791568
# GH 153

0 commit comments

Comments
 (0)