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 ,
@@ -229,7 +227,6 @@ def test_logical_compat(self, simple_index):
229227 with pytest .raises (TypeError , match = msg ):
230228 idx .any ()
231229
232- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
233230 def test_repr_roundtrip (self , simple_index ):
234231 if isinstance (simple_index , IntervalIndex ):
235232 pytest .skip (f"Not a valid repr for { type (simple_index ).__name__ } " )
@@ -246,11 +243,6 @@ def test_repr_max_seq_item_setting(self, simple_index):
246243 repr (idx )
247244 assert "..." not in str (idx )
248245
249- @pytest .mark .xfail (
250- using_string_dtype () and not HAS_PYARROW ,
251- reason = "TODO(infer_string)" ,
252- strict = False ,
253- )
254246 @pytest .mark .filterwarnings (r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning" )
255247 def test_ensure_copied_data (self , index ):
256248 # Check the "copy" argument of each Index.__new__ is honoured
@@ -296,7 +288,9 @@ def test_ensure_copied_data(self, index):
296288 tm .assert_numpy_array_equal (
297289 index ._values ._mask , result ._values ._mask , check_same = "same"
298290 )
299- elif index .dtype == "string[python]" :
291+ elif (
292+ isinstance (index .dtype , StringDtype ) and index .dtype .storage == "python"
293+ ):
300294 assert np .shares_memory (index ._values ._ndarray , result ._values ._ndarray )
301295 tm .assert_numpy_array_equal (
302296 index ._values ._ndarray , result ._values ._ndarray , check_same = "same"
@@ -444,11 +438,7 @@ def test_insert_base(self, index):
444438 result = trimmed .insert (0 , index [0 ])
445439 assert index [0 :4 ].equals (result )
446440
447- @pytest .mark .skipif (
448- using_string_dtype (),
449- reason = "completely different behavior, tested elsewher" ,
450- )
451- def test_insert_out_of_bounds (self , index ):
441+ def test_insert_out_of_bounds (self , index , using_infer_string ):
452442 # TypeError/IndexError matches what np.insert raises in these cases
453443
454444 if len (index ) > 0 :
@@ -460,6 +450,12 @@ def test_insert_out_of_bounds(self, index):
460450 msg = "index (0|0.5) is out of bounds for axis 0 with size 0"
461451 else :
462452 msg = "slice indices must be integers or None or have an __index__ method"
453+
454+ if using_infer_string and (
455+ index .dtype == "string" or index .dtype == "category" # noqa: PLR1714
456+ ):
457+ msg = "loc must be an integer between"
458+
463459 with pytest .raises (err , match = msg ):
464460 index .insert (0.5 , "foo" )
465461
0 commit comments