66import numpy as np
77import pytest
88
9- from pandas ._config import using_string_dtype
10-
119from pandas ._libs .tslibs import Timestamp
12- from pandas .compat import HAS_PYARROW
1310
1411from pandas .core .dtypes .common import (
1512 is_integer_dtype ,
2825 PeriodIndex ,
2926 RangeIndex ,
3027 Series ,
28+ StringDtype ,
3129 TimedeltaIndex ,
3230 isna ,
3331 period_range ,
@@ -233,7 +231,6 @@ def test_logical_compat(self, simple_index):
233231 with pytest .raises (TypeError , match = msg ):
234232 idx .any ()
235233
236- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
237234 def test_repr_roundtrip (self , simple_index ):
238235 if isinstance (simple_index , IntervalIndex ):
239236 pytest .skip (f"Not a valid repr for { type (simple_index ).__name__ } " )
@@ -250,11 +247,6 @@ def test_repr_max_seq_item_setting(self, simple_index):
250247 repr (idx )
251248 assert "..." not in str (idx )
252249
253- @pytest .mark .xfail (
254- using_string_dtype () and not HAS_PYARROW ,
255- reason = "TODO(infer_string)" ,
256- strict = False ,
257- )
258250 @pytest .mark .filterwarnings (r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning" )
259251 def test_ensure_copied_data (self , index ):
260252 # Check the "copy" argument of each Index.__new__ is honoured
@@ -302,7 +294,9 @@ def test_ensure_copied_data(self, index):
302294 tm .assert_numpy_array_equal (
303295 index ._values ._mask , result ._values ._mask , check_same = "same"
304296 )
305- elif index .dtype == "string[python]" :
297+ elif (
298+ isinstance (index .dtype , StringDtype ) and index .dtype .storage == "python"
299+ ):
306300 assert np .shares_memory (index ._values ._ndarray , result ._values ._ndarray )
307301 tm .assert_numpy_array_equal (
308302 index ._values ._ndarray , result ._values ._ndarray , check_same = "same"
@@ -432,11 +426,7 @@ def test_insert_base(self, index):
432426 result = trimmed .insert (0 , index [0 ])
433427 assert index [0 :4 ].equals (result )
434428
435- @pytest .mark .skipif (
436- using_string_dtype (),
437- reason = "completely different behavior, tested elsewher" ,
438- )
439- def test_insert_out_of_bounds (self , index ):
429+ def test_insert_out_of_bounds (self , index , using_infer_string ):
440430 # TypeError/IndexError matches what np.insert raises in these cases
441431
442432 if len (index ) > 0 :
@@ -448,6 +438,12 @@ def test_insert_out_of_bounds(self, index):
448438 msg = "index (0|0.5) is out of bounds for axis 0 with size 0"
449439 else :
450440 msg = "slice indices must be integers or None or have an __index__ method"
441+
442+ if using_infer_string and (
443+ index .dtype == "string" or index .dtype == "category" # noqa: PLR1714
444+ ):
445+ msg = "loc must be an integer between"
446+
451447 with pytest .raises (err , match = msg ):
452448 index .insert (0.5 , "foo" )
453449
0 commit comments