Skip to content

Commit 8cb79b0

Browse files
committed
replace Series[Any] with Series
1 parent e67aaa9 commit 8cb79b0

File tree

9 files changed

+51
-54
lines changed

9 files changed

+51
-54
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ mypy round.py
4545
we get the following error message:
4646

4747
```text
48-
round.py:6: error: Argument "decimals" to "round" of "DataFrame" has incompatible type "DataFrame"; expected "Union[int, Dict[Any, Any], Series[Any]]" [arg-type]
48+
round.py:6: error: Argument "decimals" to "round" of "DataFrame" has incompatible type "DataFrame"; expected "Union[int, Dict[Any, Any], Series]" [arg-type]
4949
Found 1 error in 1 file (checked 1 source file)
5050
```
5151

docs/philosophy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ lt = s < 3
2929

3030
In the pandas source, `lt` is a `Series` with a `dtype` of `bool`. In the pandas-stubs,
3131
the type of `lt` is `Series[bool]`. This allows further type checking to occur in other
32-
pandas methods. Note that in the above example, `s` is typed as `Series[Any]` because
32+
pandas methods. Note that in the above example, `s` is typed as `Series` because
3333
its type cannot be statically inferred.
3434

3535
This also allows type checking for operations on series that contain date/time data. Consider

pandas-stubs/_typing.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ HashableT5 = TypeVar("HashableT5", bound=Hashable)
6565
# array-like
6666

6767
ArrayLike: TypeAlias = ExtensionArray | np.ndarray
68-
AnyArrayLike: TypeAlias = ArrayLike | Index[Any] | Series[Any]
68+
AnyArrayLike: TypeAlias = ArrayLike | Index[Any] | Series
6969

7070
# list-like
7171

@@ -950,7 +950,7 @@ ReplaceValue: TypeAlias = (
950950
| NAType
951951
| Sequence[Scalar | Pattern]
952952
| Mapping[HashableT, ScalarT]
953-
| Series[Any]
953+
| Series
954954
| None
955955
)
956956

pandas-stubs/core/dtypes/missing.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ isneginf_scalar = ...
2626
@overload
2727
def isna(obj: DataFrame) -> DataFrame: ...
2828
@overload
29-
def isna(obj: Series[Any]) -> Series[bool]: ...
29+
def isna(obj: Series) -> Series[bool]: ...
3030
@overload
3131
def isna(obj: Index[Any] | list[Any] | ArrayLike) -> npt.NDArray[np.bool_]: ...
3232
@overload
@@ -39,7 +39,7 @@ isnull = isna
3939
@overload
4040
def notna(obj: DataFrame) -> DataFrame: ...
4141
@overload
42-
def notna(obj: Series[Any]) -> Series[bool]: ...
42+
def notna(obj: Series) -> Series[bool]: ...
4343
@overload
4444
def notna(obj: Index[Any] | list[Any] | ArrayLike) -> npt.NDArray[np.bool_]: ...
4545
@overload

pandas-stubs/core/frame.pyi

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,11 +1317,11 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
13171317
@overload
13181318
def stack(
13191319
self, level: Level | list[Level] = ..., dropna: _bool = ..., sort: _bool = ...
1320-
) -> Self | Series[Any]: ...
1320+
) -> Self | Series: ...
13211321
@overload
13221322
def stack(
13231323
self, level: Level | list[Level] = ..., future_stack: _bool = ...
1324-
) -> Self | Series[Any]: ...
1324+
) -> Self | Series: ...
13251325
def explode(
13261326
self, column: Sequence[Hashable], ignore_index: _bool = ...
13271327
) -> Self: ...
@@ -1381,7 +1381,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
13811381
@overload
13821382
def apply(
13831383
self,
1384-
f: Callable[..., ListLikeExceptSeriesAndStr | Series[Any]],
1384+
f: Callable[..., ListLikeExceptSeriesAndStr | Series],
13851385
axis: AxisIndex = ...,
13861386
raw: _bool = ...,
13871387
result_type: None = ...,
@@ -1409,7 +1409,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
14091409
result_type: None = ...,
14101410
args: Any = ...,
14111411
**kwargs: Any,
1412-
) -> Series[Any]: ...
1412+
) -> Series: ...
14131413

14141414
# apply() overloads with keyword result_type, and axis does not matter
14151415
@overload
@@ -1426,7 +1426,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
14261426
@overload
14271427
def apply(
14281428
self,
1429-
f: Callable[..., ListLikeExceptSeriesAndStr | Series[Any] | Mapping[Any, Any]],
1429+
f: Callable[..., ListLikeExceptSeriesAndStr | Series | Mapping[Any, Any]],
14301430
axis: Axis = ...,
14311431
raw: _bool = ...,
14321432
args: Any = ...,
@@ -1444,12 +1444,12 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
14441444
*,
14451445
result_type: Literal["reduce"],
14461446
**kwargs: Any,
1447-
) -> Series[Any]: ...
1447+
) -> Series: ...
14481448
@overload
14491449
def apply(
14501450
self,
14511451
f: Callable[
1452-
..., ListLikeExceptSeriesAndStr | Series[Any] | Scalar | Mapping[Any, Any]
1452+
..., ListLikeExceptSeriesAndStr | Series | Scalar | Mapping[Any, Any]
14531453
],
14541454
axis: Axis = ...,
14551455
raw: _bool = ...,
@@ -1463,14 +1463,14 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
14631463
@overload
14641464
def apply(
14651465
self,
1466-
f: Callable[..., Series[Any]],
1466+
f: Callable[..., Series],
14671467
axis: AxisIndex = ...,
14681468
raw: _bool = ...,
14691469
args: Any = ...,
14701470
*,
14711471
result_type: Literal["reduce"],
14721472
**kwargs: Any,
1473-
) -> Series[Any]: ...
1473+
) -> Series: ...
14741474

14751475
# apply() overloads with default result_type of None, and keyword axis=1 matters
14761476
@overload
@@ -1494,11 +1494,11 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
14941494
*,
14951495
axis: AxisColumn,
14961496
**kwargs: Any,
1497-
) -> Series[Any]: ...
1497+
) -> Series: ...
14981498
@overload
14991499
def apply(
15001500
self,
1501-
f: Callable[..., Series[Any]],
1501+
f: Callable[..., Series],
15021502
raw: _bool = ...,
15031503
result_type: None = ...,
15041504
args: Any = ...,
@@ -1511,7 +1511,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
15111511
@overload
15121512
def apply(
15131513
self,
1514-
f: Callable[..., Series[Any]],
1514+
f: Callable[..., Series],
15151515
raw: _bool = ...,
15161516
args: Any = ...,
15171517
*,
@@ -1536,7 +1536,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
15361536
) -> Self: ...
15371537
def merge(
15381538
self,
1539-
right: DataFrame | Series[Any],
1539+
right: DataFrame | Series,
15401540
how: MergeHow = ...,
15411541
on: IndexLabel | AnyArrayLike | None = ...,
15421542
left_on: IndexLabel | AnyArrayLike | None = ...,

pandas-stubs/core/reshape/concat.pyi

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ from collections.abc import (
44
Sequence,
55
)
66
from typing import (
7-
Any,
87
Literal,
98
overload,
109
)
@@ -40,7 +39,7 @@ def concat( # type: ignore[overload-overlap]
4039
) -> DataFrame: ...
4140
@overload
4241
def concat( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
43-
objs: Iterable[Series[Any]] | Mapping[HashableT1, Series[Any]],
42+
objs: Iterable[Series] | Mapping[HashableT1, Series],
4443
*,
4544
axis: AxisIndex = ...,
4645
join: Literal["inner", "outer"] = ...,
@@ -51,12 +50,10 @@ def concat( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappin
5150
verify_integrity: bool = ...,
5251
sort: bool = ...,
5352
copy: bool = ...,
54-
) -> Series[Any]: ...
53+
) -> Series: ...
5554
@overload
5655
def concat( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
57-
objs: (
58-
Iterable[Series[Any] | DataFrame] | Mapping[HashableT1, Series[Any] | DataFrame]
59-
),
56+
objs: Iterable[Series | DataFrame] | Mapping[HashableT1, Series | DataFrame],
6057
*,
6158
axis: Axis = ...,
6259
join: Literal["inner", "outer"] = ...,
@@ -98,7 +95,7 @@ def concat( # type: ignore[overload-overlap]
9895
) -> DataFrame: ...
9996
@overload
10097
def concat( # type: ignore[overload-overlap]
101-
objs: Iterable[Series[Any] | None] | Mapping[HashableT1, Series[Any] | None],
98+
objs: Iterable[Series | None] | Mapping[HashableT1, Series | None],
10299
*,
103100
axis: AxisIndex = ...,
104101
join: Literal["inner", "outer"] = ...,
@@ -109,12 +106,12 @@ def concat( # type: ignore[overload-overlap]
109106
verify_integrity: bool = ...,
110107
sort: bool = ...,
111108
copy: bool = ...,
112-
) -> Series[Any]: ...
109+
) -> Series: ...
113110
@overload
114111
def concat(
115112
objs: (
116-
Iterable[Series[Any] | DataFrame | None]
117-
| Mapping[HashableT1, Series[Any] | DataFrame | None]
113+
Iterable[Series | DataFrame | None]
114+
| Mapping[HashableT1, Series | DataFrame | None]
118115
),
119116
*,
120117
axis: Axis = ...,

pandas-stubs/core/series.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
13081308
dtype: ObjectDtypeArg | VoidDtypeArg | ExtensionDtype | DtypeObj,
13091309
copy: _bool = ...,
13101310
errors: IgnoreRaise = ...,
1311-
) -> Series[Any]: ...
1311+
) -> Series: ...
13121312
def copy(self, deep: _bool = ...) -> Series[S1]: ...
13131313
def infer_objects(self) -> Series[S1]: ...
13141314
@overload

tests/test_frame.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def test_assign() -> None:
317317
def my_named_func_1(df: pd.DataFrame) -> pd.Series[str]:
318318
return df["a"]
319319

320-
def my_named_func_2(df: pd.DataFrame) -> pd.Series[Any]:
320+
def my_named_func_2(df: pd.DataFrame) -> pd.Series:
321321
return df["a"]
322322

323323
check(assert_type(df.assign(c=lambda df: df["a"] * 2), pd.DataFrame), pd.DataFrame)
@@ -3105,29 +3105,29 @@ def test_frame_stack() -> None:
31053105
):
31063106
check(
31073107
assert_type(
3108-
df_multi_level_cols2.stack(0), Union[pd.DataFrame, "pd.Series[Any]"]
3108+
df_multi_level_cols2.stack(0), Union[pd.DataFrame, "pd.Series"]
31093109
),
31103110
pd.DataFrame,
31113111
)
31123112
check(
31133113
assert_type(
31143114
df_multi_level_cols2.stack([0, 1]),
3115-
Union[pd.DataFrame, "pd.Series[Any]"],
3115+
Union[pd.DataFrame, "pd.Series"],
31163116
),
31173117
pd.Series,
31183118
)
31193119
if PD_LTE_22:
31203120
check(
31213121
assert_type(
31223122
df_multi_level_cols2.stack(0, future_stack=False),
3123-
Union[pd.DataFrame, "pd.Series[Any]"],
3123+
Union[pd.DataFrame, "pd.Series"],
31243124
),
31253125
pd.DataFrame,
31263126
)
31273127
check(
31283128
assert_type(
31293129
df_multi_level_cols2.stack(0, dropna=True, sort=True),
3130-
Union[pd.DataFrame, "pd.Series[Any]"],
3130+
Union[pd.DataFrame, "pd.Series"],
31313131
),
31323132
pd.DataFrame,
31333133
)

tests/test_series.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,13 +2872,13 @@ def test_astype_object(cast_arg: ObjectDtypeArg, target_type: type) -> None:
28722872

28732873
if TYPE_CHECKING:
28742874
# python object
2875-
assert_type(s.astype(object), "pd.Series[Any]")
2876-
assert_type(s.astype("object"), "pd.Series[Any]")
2875+
assert_type(s.astype(object), "pd.Series")
2876+
assert_type(s.astype("object"), "pd.Series")
28772877
# numpy object
2878-
assert_type(s.astype(np.object_), "pd.Series[Any]")
2879-
# assert_type(s.astype("object_"), "pd.Series[Any]") # NOTE: not assigned
2880-
# assert_type(s.astype("object0"), "pd.Series[Any]") # NOTE: not assigned
2881-
assert_type(s.astype("O"), "pd.Series[Any]")
2878+
assert_type(s.astype(np.object_), "pd.Series")
2879+
# assert_type(s.astype("object_"), "pd.Series") # NOTE: not assigned
2880+
# assert_type(s.astype("object0"), "pd.Series") # NOTE: not assigned
2881+
assert_type(s.astype("O"), "pd.Series")
28822882

28832883

28842884
@pytest.mark.parametrize("cast_arg, target_type", ASTYPE_VOID_ARGS, ids=repr)
@@ -2888,9 +2888,9 @@ def test_astype_void(cast_arg: VoidDtypeArg, target_type: type) -> None:
28882888

28892889
if TYPE_CHECKING:
28902890
# numpy void
2891-
assert_type(s.astype(np.void), "pd.Series[Any]")
2892-
assert_type(s.astype("void"), "pd.Series[Any]")
2893-
assert_type(s.astype("V"), "pd.Series[Any]")
2891+
assert_type(s.astype(np.void), "pd.Series")
2892+
assert_type(s.astype("void"), "pd.Series")
2893+
assert_type(s.astype("V"), "pd.Series")
28942894

28952895

28962896
def test_astype_other() -> None:
@@ -2902,7 +2902,7 @@ def test_astype_other() -> None:
29022902

29032903
# Test self-consistent with s.dtype (#747)
29042904
# NOTE: https://github.com/python/typing/issues/801#issuecomment-1646171898
2905-
check(assert_type(s.astype(s.dtype), "pd.Series[Any]"), pd.Series, np.integer)
2905+
check(assert_type(s.astype(s.dtype), "pd.Series"), pd.Series, np.integer)
29062906

29072907
# test DecimalDtype
29082908
orseries = pd.Series([Decimal(x) for x in [1, 2, 3]])
@@ -2917,7 +2917,7 @@ def test_astype_other() -> None:
29172917
# Test non-literal string
29182918
# NOTE: currently unsupported! Enable in future.
29192919
# string: str = "int" # not Literal!
2920-
# check(assert_type(s.astype(string), "pd.Series[Any]"), pd.Series, np.integer)
2920+
# check(assert_type(s.astype(string), "pd.Series"), pd.Series, np.integer)
29212921

29222922

29232923
def test_all_astype_args_tested() -> None:
@@ -3224,7 +3224,7 @@ def test_get() -> None:
32243224

32253225
def test_series_new_empty() -> None:
32263226
# GH 826
3227-
check(assert_type(pd.Series(), "pd.Series[Any]"), pd.Series)
3227+
check(assert_type(pd.Series(), "pd.Series"), pd.Series)
32283228

32293229

32303230
def test_series_mapping() -> None:
@@ -3406,10 +3406,10 @@ def first_arg_not_series(argument_1: int, ser: pd.Series) -> pd.Series:
34063406

34073407
def test_series_apply() -> None:
34083408
s = pd.Series(["A", "B", "AB"])
3409-
check(assert_type(s.apply(tuple), "pd.Series[Any]"), pd.Series)
3410-
check(assert_type(s.apply(list), "pd.Series[Any]"), pd.Series)
3411-
check(assert_type(s.apply(set), "pd.Series[Any]"), pd.Series)
3412-
check(assert_type(s.apply(frozenset), "pd.Series[Any]"), pd.Series)
3409+
check(assert_type(s.apply(tuple), "pd.Series"), pd.Series)
3410+
check(assert_type(s.apply(list), "pd.Series"), pd.Series)
3411+
check(assert_type(s.apply(set), "pd.Series"), pd.Series)
3412+
check(assert_type(s.apply(frozenset), "pd.Series"), pd.Series)
34133413

34143414

34153415
def test_diff() -> None:
@@ -3671,10 +3671,10 @@ class MyDict(TypedDict):
36713671

36723672

36733673
def test_series_empty_dtype() -> None:
3674-
"""Test for the creation of a Series from an empty list GH571 to map to a Series[Any]."""
3674+
"""Test for the creation of a Series from an empty list GH571 to map to a Series."""
36753675
new_tab: Sequence[Never] = [] # need to be typehinted to please mypy
3676-
check(assert_type(pd.Series(new_tab), "pd.Series[Any]"), pd.Series)
3677-
check(assert_type(pd.Series([]), "pd.Series[Any]"), pd.Series)
3676+
check(assert_type(pd.Series(new_tab), "pd.Series"), pd.Series)
3677+
check(assert_type(pd.Series([]), "pd.Series"), pd.Series)
36783678
# ensure that an empty string does not get matched to Sequence[Never]
36793679
check(assert_type(pd.Series(""), "pd.Series[str]"), pd.Series)
36803680

0 commit comments

Comments
 (0)