@@ -120,6 +120,33 @@ def test_getitem_scalar(self, data):
120
120
result = pd .Series (data )[0 ]
121
121
assert isinstance (result , data .dtype .type )
122
122
123
+ def test_getitem_invalid (self , data ):
124
+ # TODO: box over scalar, [scalar], (scalar,)?
125
+
126
+ msg = (
127
+ r"only integers, slices \(`:`\), ellipsis \(`...`\), numpy.newaxis "
128
+ r"\(`None`\) and integer or boolean arrays are valid indices"
129
+ )
130
+ with pytest .raises (IndexError , match = msg ):
131
+ data ["foo" ]
132
+ with pytest .raises (IndexError , match = msg ):
133
+ data [2.5 ]
134
+
135
+ ub = len (data )
136
+ msg = "|" .join (
137
+ [
138
+ "list index out of range" , # json
139
+ "index out of bounds" , # pyarrow
140
+ "Out of bounds access" , # Sparse
141
+ f"index { ub + 1 } is out of bounds for axis 0 with size { ub } " ,
142
+ f"index -{ ub + 1 } is out of bounds for axis 0 with size { ub } " ,
143
+ ]
144
+ )
145
+ with pytest .raises (IndexError , match = msg ):
146
+ data [ub + 1 ]
147
+ with pytest .raises (IndexError , match = msg ):
148
+ data [- ub - 1 ]
149
+
123
150
def test_getitem_scalar_na (self , data_missing , na_cmp , na_value ):
124
151
result = data_missing [0 ]
125
152
assert na_cmp (result , na_value )
0 commit comments