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 ,
@@ -233,7 +231,6 @@ def test_logical_compat(self, simple_index):
233
231
with pytest .raises (TypeError , match = msg ):
234
232
idx .any ()
235
233
236
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
237
234
def test_repr_roundtrip (self , simple_index ):
238
235
if isinstance (simple_index , IntervalIndex ):
239
236
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):
250
247
repr (idx )
251
248
assert "..." not in str (idx )
252
249
253
- @pytest .mark .xfail (
254
- using_string_dtype () and not HAS_PYARROW ,
255
- reason = "TODO(infer_string)" ,
256
- strict = False ,
257
- )
258
250
@pytest .mark .filterwarnings (r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning" )
259
251
def test_ensure_copied_data (self , index ):
260
252
# Check the "copy" argument of each Index.__new__ is honoured
@@ -302,7 +294,9 @@ def test_ensure_copied_data(self, index):
302
294
tm .assert_numpy_array_equal (
303
295
index ._values ._mask , result ._values ._mask , check_same = "same"
304
296
)
305
- elif index .dtype == "string[python]" :
297
+ elif (
298
+ isinstance (index .dtype , StringDtype ) and index .dtype .storage == "python"
299
+ ):
306
300
assert np .shares_memory (index ._values ._ndarray , result ._values ._ndarray )
307
301
tm .assert_numpy_array_equal (
308
302
index ._values ._ndarray , result ._values ._ndarray , check_same = "same"
@@ -432,11 +426,7 @@ def test_insert_base(self, index):
432
426
result = trimmed .insert (0 , index [0 ])
433
427
assert index [0 :4 ].equals (result )
434
428
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 ):
440
430
# TypeError/IndexError matches what np.insert raises in these cases
441
431
442
432
if len (index ) > 0 :
@@ -448,6 +438,12 @@ def test_insert_out_of_bounds(self, index):
448
438
msg = "index (0|0.5) is out of bounds for axis 0 with size 0"
449
439
else :
450
440
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
+
451
447
with pytest .raises (err , match = msg ):
452
448
index .insert (0.5 , "foo" )
453
449
0 commit comments