6
6
import numpy as np
7
7
import pytest
8
8
9
- from pandas ._config import using_string_dtype
10
-
11
9
from pandas ._libs .tslibs import Timestamp
12
- from pandas .compat import HAS_PYARROW
13
10
14
11
from pandas .core .dtypes .common import (
15
12
is_integer_dtype ,
28
25
PeriodIndex ,
29
26
RangeIndex ,
30
27
Series ,
28
+ StringDtype ,
31
29
TimedeltaIndex ,
32
30
isna ,
33
31
period_range ,
@@ -229,7 +227,6 @@ def test_logical_compat(self, simple_index):
229
227
with pytest .raises (TypeError , match = msg ):
230
228
idx .any ()
231
229
232
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
233
230
def test_repr_roundtrip (self , simple_index ):
234
231
if isinstance (simple_index , IntervalIndex ):
235
232
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):
246
243
repr (idx )
247
244
assert "..." not in str (idx )
248
245
249
- @pytest .mark .xfail (
250
- using_string_dtype () and not HAS_PYARROW ,
251
- reason = "TODO(infer_string)" ,
252
- strict = False ,
253
- )
254
246
@pytest .mark .filterwarnings (r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning" )
255
247
def test_ensure_copied_data (self , index ):
256
248
# Check the "copy" argument of each Index.__new__ is honoured
@@ -296,7 +288,9 @@ def test_ensure_copied_data(self, index):
296
288
tm .assert_numpy_array_equal (
297
289
index ._values ._mask , result ._values ._mask , check_same = "same"
298
290
)
299
- elif index .dtype == "string[python]" :
291
+ elif (
292
+ isinstance (index .dtype , StringDtype ) and index .dtype .storage == "python"
293
+ ):
300
294
assert np .shares_memory (index ._values ._ndarray , result ._values ._ndarray )
301
295
tm .assert_numpy_array_equal (
302
296
index ._values ._ndarray , result ._values ._ndarray , check_same = "same"
@@ -444,11 +438,7 @@ def test_insert_base(self, index):
444
438
result = trimmed .insert (0 , index [0 ])
445
439
assert index [0 :4 ].equals (result )
446
440
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 ):
452
442
# TypeError/IndexError matches what np.insert raises in these cases
453
443
454
444
if len (index ) > 0 :
@@ -460,6 +450,12 @@ def test_insert_out_of_bounds(self, index):
460
450
msg = "index (0|0.5) is out of bounds for axis 0 with size 0"
461
451
else :
462
452
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
+
463
459
with pytest .raises (err , match = msg ):
464
460
index .insert (0.5 , "foo" )
465
461
0 commit comments