Skip to content

Commit 0ec28be

Browse files
authored
CLN: FrameOrSeries(Union) (#272)
* CLN: FrameOrSeries(Union) * let nightly pass for now; clean _typing a tiny bit * revert workflow changes
1 parent 64575f5 commit 0ec28be

File tree

8 files changed

+90
-100
lines changed

8 files changed

+90
-100
lines changed

pandas-stubs/_typing.pyi

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ from typing import (
2727
import numpy as np
2828
from numpy import typing as npt
2929
from pandas.core.arrays import ExtensionArray
30-
from pandas.core.frame import DataFrame
3130
from pandas.core.generic import NDFrame
3231
from pandas.core.indexes.base import Index
3332
from pandas.core.series import Series
@@ -80,14 +79,10 @@ class WriteExcelBuffer(WriteBuffer[bytes], Protocol):
8079
def truncate(self, size: Union[int, None] = ...) -> int: ...
8180

8281
FilePath = Union[str, PathLike[str]]
82+
FilePathOrBuffer = Union[
83+
FilePath, IO[AnyStr], RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper, mmap
84+
]
8385

84-
Buffer = Union[IO[AnyStr], RawIOBase, BufferedIOBase, TextIOBase, TextIOWrapper, mmap]
85-
FileOrBuffer = Union[str, Buffer[AnyStr]]
86-
FilePathOrBuffer = Union[PathLike[str], FileOrBuffer[AnyStr]]
87-
FilePathOrBytesBuffer = Union[PathLike[str], WriteBuffer[bytes]]
88-
89-
FrameOrSeries = TypeVar("FrameOrSeries", bound=NDFrame)
90-
FrameOrSeriesUnion = Union[DataFrame, Series]
9186
Axis = Union[str, int]
9287
IndexLabel = Union[Hashable, Sequence[Hashable]]
9388
Label = Optional[Hashable]
@@ -130,21 +125,9 @@ Scalar = Union[
130125
]
131126
ScalarT = TypeVar("ScalarT", bound=Scalar)
132127
# Refine the definitions below in 3.9 to use the specialized type.
133-
np_ndarray_int8 = npt.NDArray[np.int8]
134-
np_ndarray_int16 = npt.NDArray[np.int16]
135-
np_ndarray_int32 = npt.NDArray[np.int32]
136128
np_ndarray_int64 = npt.NDArray[np.int64]
137-
np_ndarray_uint8 = npt.NDArray[np.uint8]
138-
np_ndarray_uint16 = npt.NDArray[np.uint16]
139-
np_ndarray_uint32 = npt.NDArray[np.uint32]
140-
np_ndarray_uint64 = npt.NDArray[np.uint64]
141-
np_ndarray_int = Union[
142-
np_ndarray_int8, np_ndarray_int16, np_ndarray_int32, np_ndarray_int64
143-
]
144-
np_ndarray_uint = Union[
145-
np_ndarray_uint8, np_ndarray_uint16, np_ndarray_uint32, np_ndarray_uint64
146-
]
147-
np_ndarray_anyint = Union[np_ndarray_int, np_ndarray_uint]
129+
np_ndarray_int = npt.NDArray[np.signedinteger]
130+
np_ndarray_anyint = npt.NDArray[np.integer]
148131
np_ndarray_bool = npt.NDArray[np.bool_]
149132
np_ndarray_str = npt.NDArray[np.str_]
150133

pandas-stubs/core/generic.pyi

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ from typing import (
1212
)
1313

1414
import numpy as np
15+
from pandas import (
16+
DataFrame,
17+
Index,
18+
)
1519
from pandas.core.base import PandasObject
16-
from pandas.core.indexes.base import Index
1720
import pandas.core.indexing as indexing
1821
import sqlalchemy.engine
1922

@@ -29,8 +32,6 @@ from pandas._typing import (
2932
FilePathOrBuffer,
3033
FileWriteMode,
3134
FillnaOptions,
32-
FrameOrSeries,
33-
FrameOrSeriesUnion,
3435
HashableT,
3536
HDFCompLib,
3637
IgnoreRaise,
@@ -55,11 +56,11 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
5556
__hash__: ClassVar[None] # type: ignore[assignment]
5657

5758
def set_flags(
58-
self: FrameOrSeries,
59+
self: NDFrameT,
5960
*,
6061
copy: bool = ...,
6162
allows_duplicate_labels: bool | None = ...,
62-
) -> FrameOrSeries: ...
63+
) -> NDFrameT: ...
6364
@property
6465
def attrs(self) -> dict[Hashable | None, Any]: ...
6566
@attrs.setter
@@ -290,7 +291,7 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
290291
axis: SeriesAxisType = ...,
291292
level: Level | None = ...,
292293
drop_level: _bool = ...,
293-
) -> FrameOrSeriesUnion: ...
294+
) -> DataFrame | Series: ...
294295
def __delitem__(self, idx: Hashable): ...
295296
def get(self, key: object, default: Dtype | None = ...) -> Dtype: ...
296297
def reindex_like(
@@ -357,8 +358,8 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
357358
regex: _str | None = ...,
358359
axis=...,
359360
) -> NDFrame: ...
360-
def head(self: FrameOrSeries, n: int = ...) -> FrameOrSeries: ...
361-
def tail(self: FrameOrSeries, n: int = ...) -> FrameOrSeries: ...
361+
def head(self: NDFrameT, n: int = ...) -> NDFrameT: ...
362+
def tail(self: NDFrameT, n: int = ...) -> NDFrameT: ...
362363
def pipe(
363364
self, func: Callable[..., T] | tuple[Callable[..., T], str], *args, **kwargs
364365
) -> T: ...
@@ -369,22 +370,22 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
369370
@property
370371
def dtypes(self): ...
371372
def astype(
372-
self: FrameOrSeries,
373+
self: NDFrameT,
373374
dtype,
374375
copy: _bool = ...,
375376
errors: IgnoreRaise = ...,
376-
) -> FrameOrSeries: ...
377-
def copy(self: FrameOrSeries, deep: _bool = ...) -> FrameOrSeries: ...
377+
) -> NDFrameT: ...
378+
def copy(self: NDFrameT, deep: _bool = ...) -> NDFrameT: ...
378379
def __copy__(self, deep: _bool = ...) -> NDFrame: ...
379380
def __deepcopy__(self, memo=...) -> NDFrame: ...
380381
def infer_objects(self) -> NDFrame: ...
381382
def convert_dtypes(
382-
self: FrameOrSeries,
383+
self: NDFrameT,
383384
infer_objects: _bool = ...,
384385
convert_string: _bool = ...,
385386
convert_integer: _bool = ...,
386387
convert_boolean: _bool = ...,
387-
) -> FrameOrSeries: ...
388+
) -> NDFrameT: ...
388389
def fillna(
389390
self,
390391
value=...,

pandas-stubs/core/groupby/generic.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ from matplotlib.axes import (
1717
)
1818
import numpy as np
1919
from pandas.core.frame import DataFrame
20+
from pandas.core.generic import NDFrame
2021
from pandas.core.groupby.groupby import ( # , get_groupby as get_groupby
2122
GroupBy as GroupBy,
2223
)
@@ -28,7 +29,6 @@ from pandas._typing import (
2829
AggFuncType,
2930
AggFuncTypeBase,
3031
AxisType,
31-
FrameOrSeries,
3232
Level,
3333
ListLike,
3434
Scalar,
@@ -41,7 +41,7 @@ class NamedAgg(NamedTuple):
4141
column: str = ...
4242
aggfunc: AggScalar = ...
4343

44-
def generate_property(name: str, klass: type[FrameOrSeries]): ...
44+
def generate_property(name: str, klass: type[NDFrame]): ...
4545

4646
class _SeriesGroupByScalar(SeriesGroupBy[S1]):
4747
def __iter__(self) -> Iterator[tuple[Scalar, Series]]: ...

pandas-stubs/core/groupby/groupby.pyi

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ from pandas.core.series import Series
1212

1313
from pandas._typing import (
1414
AxisType,
15-
FrameOrSeriesUnion,
1615
KeysArgType,
1716
NDFrameT,
1817
)
@@ -63,24 +62,24 @@ class BaseGroupBy(PandasObject, SelectionMixin[NDFrameT]):
6362
def get_group(self, name, obj: DataFrame | None = ...) -> DataFrame: ...
6463

6564
class GroupBy(BaseGroupBy[NDFrameT]):
66-
def count(self) -> FrameOrSeriesUnion: ...
67-
def mean(self, **kwargs) -> FrameOrSeriesUnion: ...
68-
def median(self, **kwargs) -> FrameOrSeriesUnion: ...
69-
def std(self, ddof: int = ...) -> FrameOrSeriesUnion: ...
70-
def var(self, ddof: int = ...) -> FrameOrSeriesUnion: ...
71-
def sem(self, ddof: int = ...) -> FrameOrSeriesUnion: ...
65+
def count(self) -> DataFrame | Series: ...
66+
def mean(self, **kwargs) -> DataFrame | Series: ...
67+
def median(self, **kwargs) -> DataFrame | Series: ...
68+
def std(self, ddof: int = ...) -> DataFrame | Series: ...
69+
def var(self, ddof: int = ...) -> DataFrame | Series: ...
70+
def sem(self, ddof: int = ...) -> DataFrame | Series: ...
7271
def ohlc(self) -> DataFrame: ...
73-
def describe(self, **kwargs) -> FrameOrSeriesUnion: ...
72+
def describe(self, **kwargs) -> DataFrame | Series: ...
7473
def resample(self, rule, *args, **kwargs): ...
7574
def rolling(self, *args, **kwargs): ...
7675
def expanding(self, *args, **kwargs): ...
7776
def pad(self, limit: int | None = ...): ...
78-
def ffill(self, limit: int | None = ...) -> FrameOrSeriesUnion: ...
79-
def backfill(self, limit: int | None = ...) -> FrameOrSeriesUnion: ...
80-
def bfill(self, limit: int | None = ...) -> FrameOrSeriesUnion: ...
77+
def ffill(self, limit: int | None = ...) -> DataFrame | Series: ...
78+
def backfill(self, limit: int | None = ...) -> DataFrame | Series: ...
79+
def bfill(self, limit: int | None = ...) -> DataFrame | Series: ...
8180
def nth(
8281
self, n: int | list[int], dropna: str | None = ...
83-
) -> FrameOrSeriesUnion: ...
82+
) -> DataFrame | Series: ...
8483
def quantile(self, q=..., interpolation: str = ...): ...
8584
def ngroup(self, ascending: bool = ...) -> Series: ...
8685
def cumcount(self, ascending: bool = ...) -> Series: ...
@@ -92,10 +91,10 @@ class GroupBy(BaseGroupBy[NDFrameT]):
9291
pct: bool = ...,
9392
axis: int = ...,
9493
) -> DataFrame: ...
95-
def cummax(self, axis: AxisType = ..., **kwargs) -> FrameOrSeriesUnion: ...
96-
def cummin(self, axis: AxisType = ..., **kwargs) -> FrameOrSeriesUnion: ...
97-
def cumprod(self, axis: AxisType = ..., **kwargs) -> FrameOrSeriesUnion: ...
98-
def cumsum(self, axis: AxisType = ..., **kwargs) -> FrameOrSeriesUnion: ...
94+
def cummax(self, axis: AxisType = ..., **kwargs) -> DataFrame | Series: ...
95+
def cummin(self, axis: AxisType = ..., **kwargs) -> DataFrame | Series: ...
96+
def cumprod(self, axis: AxisType = ..., **kwargs) -> DataFrame | Series: ...
97+
def cumsum(self, axis: AxisType = ..., **kwargs) -> DataFrame | Series: ...
9998
def shift(
10099
self, periods: int = ..., freq=..., axis: AxisType = ..., fill_value=...
101100
): ...
@@ -106,14 +105,14 @@ class GroupBy(BaseGroupBy[NDFrameT]):
106105
limit=...,
107106
freq=...,
108107
axis: AxisType = ...,
109-
) -> FrameOrSeriesUnion: ...
110-
def head(self, n: int = ...) -> FrameOrSeriesUnion: ...
111-
def tail(self, n: int = ...) -> FrameOrSeriesUnion: ...
108+
) -> DataFrame | Series: ...
109+
def head(self, n: int = ...) -> DataFrame | Series: ...
110+
def tail(self, n: int = ...) -> DataFrame | Series: ...
112111
# Surplus methodss from original pylance stubs; should they go away?
113-
def first(self, **kwargs) -> FrameOrSeriesUnion: ...
114-
def last(self, **kwargs) -> FrameOrSeriesUnion: ...
115-
def max(self, **kwargs) -> FrameOrSeriesUnion: ...
116-
def min(self, **kwargs) -> FrameOrSeriesUnion: ...
112+
def first(self, **kwargs) -> DataFrame | Series: ...
113+
def last(self, **kwargs) -> DataFrame | Series: ...
114+
def max(self, **kwargs) -> DataFrame | Series: ...
115+
def min(self, **kwargs) -> DataFrame | Series: ...
117116
def size(self) -> Series[int]: ...
118117

119118
def get_groupby(

pandas-stubs/core/groupby/grouper.pyi

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from typing import Hashable
22

33
import numpy as np
4+
from pandas import (
5+
DataFrame,
6+
Index,
7+
Series,
8+
)
49
from pandas.core.groupby.ops import BaseGrouper
5-
from pandas.core.indexes.api import Index
610

7-
from pandas._typing import (
8-
FrameOrSeries,
9-
FrameOrSeriesUnion,
10-
)
11+
from pandas._typing import NDFrameT
1112

1213
class Grouper:
1314
def __new__(cls, *args, **kwargs): ...
@@ -42,7 +43,7 @@ class Grouping:
4243
self,
4344
index: Index,
4445
grouper=...,
45-
obj: FrameOrSeriesUnion | None = ...,
46+
obj: DataFrame | Series | None = ...,
4647
name=...,
4748
level=...,
4849
sort: bool = ...,
@@ -61,12 +62,12 @@ class Grouping:
6162
def groups(self) -> dict[Hashable, np.ndarray]: ...
6263

6364
def get_grouper(
64-
obj: FrameOrSeries,
65+
obj: NDFrameT,
6566
key=...,
6667
axis: int = ...,
6768
level=...,
6869
sort: bool = ...,
6970
observed: bool = ...,
7071
mutated: bool = ...,
7172
validate: bool = ...,
72-
) -> tuple[BaseGrouper, list[Hashable], FrameOrSeries]: ...
73+
) -> tuple[BaseGrouper, list[Hashable], NDFrameT]: ...

pandas-stubs/core/groupby/ops.pyi

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from typing import Sequence
22

33
import numpy as np
4+
from pandas import (
5+
DataFrame,
6+
Index,
7+
Series,
8+
)
49
from pandas.core.groupby import grouper
5-
from pandas.core.indexes.api import Index
6-
from pandas.core.series import Series
7-
8-
from pandas._typing import FrameOrSeriesUnion
910

1011
class BaseGrouper:
1112
axis = ...
@@ -29,8 +30,8 @@ class BaseGrouper:
2930
def __iter__(self): ...
3031
@property
3132
def nkeys(self) -> int: ...
32-
def get_iterator(self, data: FrameOrSeriesUnion, axis: int = ...): ...
33-
def apply(self, f, data: FrameOrSeriesUnion, axis: int = ...): ...
33+
def get_iterator(self, data: DataFrame | Series, axis: int = ...): ...
34+
def apply(self, f, data: DataFrame | Series, axis: int = ...): ...
3435
def indices(self): ...
3536
@property
3637
def codes(self) -> list[np.ndarray]: ...
@@ -66,7 +67,7 @@ class BinGrouper(BaseGrouper):
6667
def groups(self): ...
6768
@property
6869
def nkeys(self) -> int: ...
69-
def get_iterator(self, data: FrameOrSeriesUnion, axis: int = ...): ...
70+
def get_iterator(self, data: DataFrame | Series, axis: int = ...): ...
7071
def indices(self): ...
7172
def group_info(self): ...
7273
def reconstructed_codes(self) -> list[np.ndarray]: ...
@@ -85,12 +86,12 @@ class DataSplitter:
8586
ngroups = ...
8687
axis = ...
8788
def __init__(
88-
self, data: FrameOrSeriesUnion, labels, ngroups: int, axis: int = ...
89+
self, data: DataFrame | Series, labels, ngroups: int, axis: int = ...
8990
) -> None: ...
9091
def slabels(self): ...
9192
def __iter__(self): ...
9293

9394
class SeriesSplitter(DataSplitter): ...
9495
class FrameSplitter(DataSplitter): ...
9596

96-
def get_splitter(data: FrameOrSeriesUnion, *args, **kwargs) -> DataSplitter: ...
97+
def get_splitter(data: DataFrame | Series, *args, **kwargs) -> DataSplitter: ...

pandas-stubs/core/window/expanding.pyi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ from typing import (
33
Callable,
44
)
55

6+
from pandas import (
7+
DataFrame,
8+
Series,
9+
)
610
from pandas.core.window.rolling import _Rolling_and_Expanding
711

8-
from pandas._typing import FrameOrSeriesUnion as FrameOrSeries
9-
1012
class Expanding(_Rolling_and_Expanding):
1113
def __init__(
1214
self, obj, min_periods: int = ..., center: bool = ..., axis: int = ..., **kwargs
1315
) -> None: ...
14-
def count(self, **kwargs) -> FrameOrSeries: ...
16+
def count(self, **kwargs) -> DataFrame | Series: ...
1517
def apply(
1618
self,
1719
func: Callable[..., Any],

0 commit comments

Comments
 (0)