@@ -95,43 +95,14 @@ def test_scalar_non_numeric(self, index_func, klass):
95
95
s = gen_obj (klass , i )
96
96
97
97
# getting
98
- for idxr , getitem in [(lambda x : x .iloc , False ), (lambda x : x , True )]:
98
+ with pytest .raises (KeyError , match = "^3.0$" ):
99
+ s [3.0 ]
99
100
100
- if getitem :
101
- error = KeyError
102
- msg = r"^3\.0?$"
103
- else :
104
- error = TypeError
105
- msg = (
106
- r"cannot do (label|positional) indexing "
107
- fr"on { type (i ).__name__ } with these indexers \[3\.0\] of "
108
- r"type float|"
109
- "Cannot index by location index with a "
110
- "non-integer key"
111
- )
112
- with pytest .raises (error , match = msg ):
113
- idxr (s )[3.0 ]
114
-
115
- # label based can be a TypeError or KeyError
116
- if s .index .inferred_type in {
117
- "categorical" ,
118
- "string" ,
119
- "unicode" ,
120
- "mixed" ,
121
- "period" ,
122
- "timedelta64" ,
123
- "datetime64" ,
124
- }:
125
- error = KeyError
126
- msg = r"^3\.0$"
127
- else :
128
- error = TypeError
129
- msg = (
130
- r"cannot do (label|positional) indexing "
131
- fr"on { type (i ).__name__ } with these indexers \[3\.0\] of "
132
- "type float"
133
- )
134
- with pytest .raises (error , match = msg ):
101
+ msg = "Cannot index by location index with a non-integer key"
102
+ with pytest .raises (TypeError , match = msg ):
103
+ s .iloc [3.0 ]
104
+
105
+ with pytest .raises (KeyError , match = "^3.0$" ):
135
106
s .loc [3.0 ]
136
107
137
108
# contains
@@ -190,16 +161,12 @@ def test_scalar_with_mixed(self):
190
161
s2 = Series ([1 , 2 , 3 ], index = ["a" , "b" , "c" ])
191
162
s3 = Series ([1 , 2 , 3 ], index = ["a" , "b" , 1.5 ])
192
163
193
- # lookup in a pure stringstr
194
- # with an invalid indexer
195
- msg = (
196
- r"cannot do label indexing "
197
- r"on Index with these indexers \[1\.0\] of "
198
- r"type float|"
199
- "Cannot index by location index with a non-integer key"
200
- )
164
+ # lookup in a pure string index with an invalid indexer
165
+
201
166
with pytest .raises (KeyError , match = "^1.0$" ):
202
167
s2 [1.0 ]
168
+
169
+ msg = "Cannot index by location index with a non-integer key"
203
170
with pytest .raises (TypeError , match = msg ):
204
171
s2 .iloc [1.0 ]
205
172
0 commit comments