@@ -52,9 +52,6 @@ def test_setitem_ndarray_1d(self):
5252 with pytest .raises (ValueError ):
5353 df [2 :5 ] = np .arange (1 , 4 ) * 1j
5454
55- @pytest .mark .parametrize (
56- "index" , tm .all_index_generator (5 ), ids = lambda x : type (x ).__name__
57- )
5855 @pytest .mark .parametrize (
5956 "obj" ,
6057 [
@@ -71,9 +68,9 @@ def test_setitem_ndarray_1d(self):
7168 (lambda x : x .iloc , "iloc" ),
7269 ],
7370 )
74- def test_getitem_ndarray_3d (self , index , obj , idxr , idxr_id ):
71+ def test_getitem_ndarray_3d (self , indices , obj , idxr , idxr_id ):
7572 # GH 25567
76- obj = obj (index )
73+ obj = obj (indices )
7774 idxr = idxr (obj )
7875 nd3 = np .random .randint (5 , size = (2 , 2 , 2 ))
7976
@@ -83,16 +80,16 @@ def test_getitem_ndarray_3d(self, index, obj, idxr, idxr_id):
8380 "Cannot index with multidimensional key" ,
8481 r"Wrong number of dimensions. values.ndim != ndim \[3 != 1\]" ,
8582 "Index data must be 1-dimensional" ,
83+ "positional indexers are out-of-bounds" ,
84+ "Indexing a MultiIndex with a multidimensional key is not implemented" ,
8685 ]
8786 )
8887
89- with pytest .raises (ValueError , match = msg ):
88+ potential_errors = (IndexError , ValueError , NotImplementedError )
89+ with pytest .raises (potential_errors , match = msg ):
9090 with tm .assert_produces_warning (DeprecationWarning , check_stacklevel = False ):
9191 idxr [nd3 ]
9292
93- @pytest .mark .parametrize (
94- "index" , tm .all_index_generator (5 ), ids = lambda x : type (x ).__name__
95- )
9693 @pytest .mark .parametrize (
9794 "obj" ,
9895 [
@@ -109,17 +106,25 @@ def test_getitem_ndarray_3d(self, index, obj, idxr, idxr_id):
109106 (lambda x : x .iloc , "iloc" ),
110107 ],
111108 )
112- def test_setitem_ndarray_3d (self , index , obj , idxr , idxr_id ):
109+ def test_setitem_ndarray_3d (self , indices , obj , idxr , idxr_id ):
113110 # GH 25567
114- obj = obj (index )
111+ obj = obj (indices )
115112 idxr = idxr (obj )
116113 nd3 = np .random .randint (5 , size = (2 , 2 , 2 ))
117114
115+ if (
116+ (len (indices ) == 0 )
117+ and (idxr_id == "iloc" )
118+ and isinstance (obj , pd .DataFrame )
119+ ):
120+ # gh-32896
121+ pytest .skip ("This is currently failing. There's an xfailed test below." )
122+
118123 if idxr_id == "iloc" :
119124 err = ValueError
120125 msg = f"Cannot set values with ndim > { obj .ndim } "
121126 elif (
122- isinstance (index , pd .IntervalIndex )
127+ isinstance (indices , pd .IntervalIndex )
123128 and idxr_id == "setitem"
124129 and obj .ndim == 1
125130 ):
@@ -134,6 +139,17 @@ def test_setitem_ndarray_3d(self, index, obj, idxr, idxr_id):
134139 with pytest .raises (err , match = msg ):
135140 idxr [nd3 ] = 0
136141
142+ @pytest .mark .xfail (reason = "gh-32896" )
143+ def test_setitem_ndarray_3d_does_not_fail_for_iloc_empty_dataframe (self ):
144+ # when fixing this, please remove the pytest.skip in test_setitem_ndarray_3d
145+ i = Index ([])
146+ obj = DataFrame (np .random .randn (len (i ), len (i )), index = i , columns = i )
147+ nd3 = np .random .randint (5 , size = (2 , 2 , 2 ))
148+
149+ msg = f"Cannot set values with ndim > { obj .ndim } "
150+ with pytest .raises (ValueError , match = msg ):
151+ obj .iloc [nd3 ] = 0
152+
137153 def test_inf_upcast (self ):
138154 # GH 16957
139155 # We should be able to use np.inf as a key
0 commit comments