Skip to content

Commit

Permalink
BUG: Index.insert raising when inserting None into new string dtype (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl authored Oct 3, 2023
1 parent f196319 commit 8664572
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Bug fixes
- Fixed bug in :meth:`DataFrame.interpolate` raising incorrect error message (:issue:`55347`)
- Fixed bug in :meth:`DataFrame.resample` not respecting ``closed`` and ``label`` arguments for :class:`~pandas.tseries.offsets.BusinessDay` (:issue:`55282`)
- Fixed bug in :meth:`DataFrame.resample` where bin edges were not correct for :class:`~pandas.tseries.offsets.BusinessDay` (:issue:`55281`)
- Fixed bug in :meth:`Index.insert` raising when inserting ``None`` into :class:`Index` with ``dtype="string[pyarrow_numpy]"`` (:issue:`55365`)
- Silence ``Period[B]`` warnings introduced by :issue:`53446` during normal plotting activity (:issue:`55138`)
-

Expand Down
5 changes: 5 additions & 0 deletions pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,3 +613,8 @@ def _reduce(
)
else:
return super()._reduce(name, skipna=skipna, keepdims=keepdims, **kwargs)

def insert(self, loc: int, item) -> ArrowStringArrayNumpySemantics:
if item is np.nan:
item = libmissing.NA
return super().insert(loc, item) # type: ignore[return-value]
8 changes: 8 additions & 0 deletions pandas/tests/indexes/base_class/test_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ def test_insert_datetime_into_object(self, loc, val):
tm.assert_index_equal(result, expected)
assert type(expected[2]) is type(val)

def test_insert_none_into_string_numpy(self):
# GH#55365
pytest.importorskip("pyarrow")
index = Index(["a", "b", "c"], dtype="string[pyarrow_numpy]")
result = index.insert(-1, None)
expected = Index(["a", "b", None, "c"], dtype="string[pyarrow_numpy]")
tm.assert_index_equal(result, expected)

@pytest.mark.parametrize(
"pos,expected",
[
Expand Down

0 comments on commit 8664572

Please sign in to comment.