Skip to content

Commit e1ba6ad

Browse files
Add type parameter to remaining Series.astype overloads. (#949)
* Add type parameter to remaining Series.astype overloads. * Make on overload more precise. * Fix CategoricalDtype
1 parent ea8bdee commit e1ba6ad

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

pandas-stubs/core/series.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ from pandas._typing import (
158158
)
159159

160160
from pandas.core.dtypes.base import ExtensionDtype
161+
from pandas.core.dtypes.dtypes import CategoricalDtype
161162

162163
from pandas.plotting import PlotAccessor
163164

@@ -1320,14 +1321,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
13201321
dtype: CategoryDtypeArg,
13211322
copy: _bool = ...,
13221323
errors: IgnoreRaise = ...,
1323-
) -> Series: ...
1324+
) -> Series[CategoricalDtype]: ...
13241325
@overload
13251326
def astype(
13261327
self,
13271328
dtype: ObjectDtypeArg | VoidDtypeArg | ExtensionDtype | DtypeObj,
13281329
copy: _bool = ...,
13291330
errors: IgnoreRaise = ...,
1330-
) -> Series: ...
1331+
) -> Series[Any]: ...
13311332
def copy(self, deep: _bool = ...) -> Series[S1]: ...
13321333
def infer_objects(self) -> Series[S1]: ...
13331334
@overload

tests/test_series.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,8 +2581,8 @@ def test_astype_categorical(cast_arg: CategoryDtypeArg, target_type: type) -> No
25812581

25822582
if TYPE_CHECKING:
25832583
# pandas category
2584-
assert_type(s.astype(pd.CategoricalDtype()), "pd.Series[Any]")
2585-
assert_type(s.astype("category"), "pd.Series[Any]")
2584+
assert_type(s.astype(pd.CategoricalDtype()), "pd.Series[pd.CategoricalDtype]")
2585+
assert_type(s.astype("category"), "pd.Series[pd.CategoricalDtype]")
25862586
# pyarrow dictionary
25872587
# assert_type(s.astype("dictionary[pyarrow]"), "pd.Series[Categorical]")
25882588

0 commit comments

Comments
 (0)