Skip to content

Add type parameter to remaining Series.astype overloads. #949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ from pandas._typing import (
)

from pandas.core.dtypes.base import ExtensionDtype
from pandas.core.dtypes.dtypes import CategoricalDtype

from pandas.plotting import PlotAccessor

Expand Down Expand Up @@ -1320,14 +1321,14 @@ class Series(IndexOpsMixin[S1], NDFrame):
dtype: CategoryDtypeArg,
copy: _bool = ...,
errors: IgnoreRaise = ...,
) -> Series: ...
) -> Series[CategoricalDtype]: ...
@overload
def astype(
self,
dtype: ObjectDtypeArg | VoidDtypeArg | ExtensionDtype | DtypeObj,
copy: _bool = ...,
errors: IgnoreRaise = ...,
) -> Series: ...
) -> Series[Any]: ...
def copy(self, deep: _bool = ...) -> Series[S1]: ...
def infer_objects(self) -> Series[S1]: ...
@overload
Expand Down
4 changes: 2 additions & 2 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2581,8 +2581,8 @@ def test_astype_categorical(cast_arg: CategoryDtypeArg, target_type: type) -> No

if TYPE_CHECKING:
# pandas category
assert_type(s.astype(pd.CategoricalDtype()), "pd.Series[Any]")
assert_type(s.astype("category"), "pd.Series[Any]")
assert_type(s.astype(pd.CategoricalDtype()), "pd.Series[pd.CategoricalDtype]")
assert_type(s.astype("category"), "pd.Series[pd.CategoricalDtype]")
# pyarrow dictionary
# assert_type(s.astype("dictionary[pyarrow]"), "pd.Series[Categorical]")

Expand Down
Loading