2424 Index ,
2525 Int64Index ,
2626 IntervalIndex ,
27+ MultiIndex ,
2728 PeriodIndex ,
2829 Series ,
2930 TimedeltaIndex ,
@@ -140,6 +141,26 @@ def test_contains_with_float_index(self):
140141 assert 1.0 not in float_index
141142 assert 1 not in float_index
142143
144+ def test_contains_requires_hashable_raises (self , index ):
145+ if isinstance (index , MultiIndex ):
146+ return # TODO: do we want this to raise?
147+
148+ msg = "unhashable type: 'list'"
149+ with pytest .raises (TypeError , match = msg ):
150+ [] in index
151+
152+ msg = "|" .join (
153+ [
154+ r"unhashable type: 'dict'" ,
155+ r"must be real number, not dict" ,
156+ r"an integer is required" ,
157+ r"\{\}" ,
158+ r"pandas\._libs\.interval\.IntervalTree' is not iterable" ,
159+ ]
160+ )
161+ with pytest .raises (TypeError , match = msg ):
162+ {} in index ._engine
163+
143164
144165class TestGetValue :
145166 @pytest .mark .parametrize (
@@ -161,19 +182,30 @@ def test_get_value(self, index):
161182
162183
163184class TestGetIndexer :
185+ def test_get_indexer_base (self , index ):
186+
187+ if index ._index_as_unique :
188+ expected = np .arange (index .size , dtype = np .intp )
189+ actual = index .get_indexer (index )
190+ tm .assert_numpy_array_equal (expected , actual )
191+ else :
192+ msg = "Reindexing only valid with uniquely valued Index objects"
193+ with pytest .raises (InvalidIndexError , match = msg ):
194+ index .get_indexer (index )
195+
196+ with pytest .raises (ValueError , match = "Invalid fill method" ):
197+ index .get_indexer (index , method = "invalid" )
198+
164199 def test_get_indexer_consistency (self , index ):
165200 # See GH#16819
166- if isinstance (index , IntervalIndex ):
167- # requires index.is_non_overlapping
168- return
169201
170- if index .is_unique :
202+ if index ._index_as_unique :
171203 indexer = index .get_indexer (index [0 :2 ])
172204 assert isinstance (indexer , np .ndarray )
173205 assert indexer .dtype == np .intp
174206 else :
175- e = "Reindexing only valid with uniquely valued Index objects"
176- with pytest .raises (InvalidIndexError , match = e ):
207+ msg = "Reindexing only valid with uniquely valued Index objects"
208+ with pytest .raises (InvalidIndexError , match = msg ):
177209 index .get_indexer (index [0 :2 ])
178210
179211 indexer , _ = index .get_indexer_non_unique (index [0 :2 ])
@@ -197,6 +229,25 @@ def test_convert_almost_null_slice(self, index):
197229 index ._convert_slice_indexer (key , "loc" )
198230
199231
232+ class TestPutmask :
233+ def test_putmask_with_wrong_mask (self , index ):
234+ # GH#18368
235+ if not len (index ):
236+ return
237+
238+ fill = index [0 ]
239+
240+ msg = "putmask: mask and data must be the same size"
241+ with pytest .raises (ValueError , match = msg ):
242+ index .putmask (np .ones (len (index ) + 1 , np .bool_ ), fill )
243+
244+ with pytest .raises (ValueError , match = msg ):
245+ index .putmask (np .ones (len (index ) - 1 , np .bool_ ), fill )
246+
247+ with pytest .raises (ValueError , match = msg ):
248+ index .putmask ("foo" , fill )
249+
250+
200251@pytest .mark .parametrize (
201252 "idx" , [Index ([1 , 2 , 3 ]), Index ([0.1 , 0.2 , 0.3 ]), Index (["a" , "b" , "c" ])]
202253)
0 commit comments