@@ -52,9 +52,6 @@ def test_setitem_ndarray_1d(self):
52
52
with pytest .raises (ValueError ):
53
53
df [2 :5 ] = np .arange (1 , 4 ) * 1j
54
54
55
- @pytest .mark .parametrize (
56
- "index" , tm .all_index_generator (5 ), ids = lambda x : type (x ).__name__
57
- )
58
55
@pytest .mark .parametrize (
59
56
"obj" ,
60
57
[
@@ -71,9 +68,9 @@ def test_setitem_ndarray_1d(self):
71
68
(lambda x : x .iloc , "iloc" ),
72
69
],
73
70
)
74
- def test_getitem_ndarray_3d (self , index , obj , idxr , idxr_id ):
71
+ def test_getitem_ndarray_3d (self , indices , obj , idxr , idxr_id ):
75
72
# GH 25567
76
- obj = obj (index )
73
+ obj = obj (indices )
77
74
idxr = idxr (obj )
78
75
nd3 = np .random .randint (5 , size = (2 , 2 , 2 ))
79
76
@@ -83,16 +80,16 @@ def test_getitem_ndarray_3d(self, index, obj, idxr, idxr_id):
83
80
"Cannot index with multidimensional key" ,
84
81
r"Wrong number of dimensions. values.ndim != ndim \[3 != 1\]" ,
85
82
"Index data must be 1-dimensional" ,
83
+ "positional indexers are out-of-bounds" ,
84
+ "Indexing a MultiIndex with a multidimensional key is not implemented" ,
86
85
]
87
86
)
88
87
89
- with pytest .raises (ValueError , match = msg ):
88
+ potential_errors = (IndexError , ValueError , NotImplementedError )
89
+ with pytest .raises (potential_errors , match = msg ):
90
90
with tm .assert_produces_warning (DeprecationWarning , check_stacklevel = False ):
91
91
idxr [nd3 ]
92
92
93
- @pytest .mark .parametrize (
94
- "index" , tm .all_index_generator (5 ), ids = lambda x : type (x ).__name__
95
- )
96
93
@pytest .mark .parametrize (
97
94
"obj" ,
98
95
[
@@ -109,17 +106,25 @@ def test_getitem_ndarray_3d(self, index, obj, idxr, idxr_id):
109
106
(lambda x : x .iloc , "iloc" ),
110
107
],
111
108
)
112
- def test_setitem_ndarray_3d (self , index , obj , idxr , idxr_id ):
109
+ def test_setitem_ndarray_3d (self , indices , obj , idxr , idxr_id ):
113
110
# GH 25567
114
- obj = obj (index )
111
+ obj = obj (indices )
115
112
idxr = idxr (obj )
116
113
nd3 = np .random .randint (5 , size = (2 , 2 , 2 ))
117
114
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
+
118
123
if idxr_id == "iloc" :
119
124
err = ValueError
120
125
msg = f"Cannot set values with ndim > { obj .ndim } "
121
126
elif (
122
- isinstance (index , pd .IntervalIndex )
127
+ isinstance (indices , pd .IntervalIndex )
123
128
and idxr_id == "setitem"
124
129
and obj .ndim == 1
125
130
):
@@ -134,6 +139,17 @@ def test_setitem_ndarray_3d(self, index, obj, idxr, idxr_id):
134
139
with pytest .raises (err , match = msg ):
135
140
idxr [nd3 ] = 0
136
141
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
+
137
153
def test_inf_upcast (self ):
138
154
# GH 16957
139
155
# We should be able to use np.inf as a key
0 commit comments