Skip to content

Commit

Permalink
Add type parameter to remaining Series.astype overloads. (#949)
Browse files Browse the repository at this point in the history
* Add type parameter to remaining Series.astype overloads.

* Make on overload more precise.

* Fix CategoricalDtype
  • Loading branch information
JanEricNitschke committed Jun 28, 2024
1 parent ea8bdee commit e1ba6ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
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

0 comments on commit e1ba6ad

Please sign in to comment.