Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BUG: Fix cast_pointwise_result with all-NA values #62352

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

Open
heoh wants to merge 10 commits into pandas-dev:main
base: main
Choose a base branch
Loading
from heoh:gh-62344
Open
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
2 changes: 2 additions & 0 deletions pandas/core/arrays/masked.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def _from_sequence(cls, scalars, *, dtype=None, copy: bool = False) -> Self:
return cls(values, mask)

def _cast_pointwise_result(self, values) -> ArrayLike:
if isna(values).all():
return type(self)._from_sequence(values, dtype=self.dtype)
values = np.asarray(values, dtype=object)
result = lib.maybe_convert_objects(values, convert_to_nullable_dtype=True)
lkind = self.dtype.kind
Expand Down
14 changes: 11 additions & 3 deletions pandas/tests/extension/test_masked.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,15 @@ def check_accumulate(self, ser: pd.Series, op_name: str, skipna: bool):
tm.assert_series_equal(result, expected)

def test_loc_setitem_with_expansion_preserves_ea_index_dtype(self, data, request):
if data.dtype.kind == "b":
mark = pytest.mark.xfail(reason="GH#62344 incorrectly casts to object")
request.applymarker(mark)
super().test_loc_setitem_with_expansion_preserves_ea_index_dtype(data)


@pytest.mark.parametrize(
"arr", [pd.array([True, False]), pd.array([1, 2]), pd.array([1.0, 2.0])]
)
def test_cast_pointwise_result_all_na_respects_original_dtype(arr):
# GH#62344
values = [pd.NA, pd.NA]
result = arr._cast_pointwise_result(values)
assert result.dtype == arr.dtype
assert all(x is pd.NA for x in result)
Loading

AltStyle によって変換されたページ (->オリジナル) /