Skip to content

API: make FloatingArray.astype consistent with IntegerArray/BooleanArray #50028

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 1 commit into from
Dec 5, 2022
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: 0 additions & 5 deletions pandas/core/arrays/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from pandas.util._decorators import doc
from pandas.util._validators import validate_fillna_kwargs

from pandas.core.dtypes.astype import astype_nansafe
from pandas.core.dtypes.base import ExtensionDtype
from pandas.core.dtypes.common import (
is_bool,
Expand Down Expand Up @@ -492,10 +491,6 @@ def astype(self, dtype: AstypeArg, copy: bool = True) -> ArrayLike:
raise ValueError("cannot convert float NaN to bool")

data = self.to_numpy(dtype=dtype, na_value=na_value, copy=copy)
if self.dtype.kind == "f":
# TODO: make this consistent between IntegerArray/FloatingArray,
# see test_astype_str
return astype_nansafe(data, dtype, copy=False)
return data

__array_priority__ = 1000 # higher than ndarray so ops dispatch to us
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arrays/floating/test_astype.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_astype_to_integer_array():

def test_astype_str():
a = pd.array([0.1, 0.2, None], dtype="Float64")
expected = np.array(["0.1", "0.2", "<NA>"], dtype=object)
expected = np.array(["0.1", "0.2", "<NA>"], dtype="U32")

tm.assert_numpy_array_equal(a.astype(str), expected)
tm.assert_numpy_array_equal(a.astype("str"), expected)
Expand Down