@@ -1151,25 +1151,17 @@ def test_frame_iloc_setitem(self):
1151
1151
pdf .iloc [[0 , 1 , 2 ], 1 ] = - pdf .max_speed
1152
1152
self .assert_eq (kdf , pdf )
1153
1153
1154
- # TODO: matching the behavior with pandas 1.2 and uncomment below test
1155
- # with self.assertRaisesRegex(
1156
- # ValueError,
1157
- # "shape mismatch: value array of shape (3,) could not be broadcast to indexing "
1158
- # "result of shape (2,1)",
1159
- # ):
1160
- # kdf.iloc[[1, 2], [1]] = -another_kdf.max_speed
1154
+ with self .assertRaisesRegex (
1155
+ ValueError , "shape mismatch" ,
1156
+ ):
1157
+ kdf .iloc [[1 , 2 ], [1 ]] = - another_kdf .max_speed
1161
1158
1162
1159
kdf .iloc [[0 , 1 , 2 ], 1 ] = 10 * another_kdf .max_speed
1163
1160
pdf .iloc [[0 , 1 , 2 ], 1 ] = 10 * pdf .max_speed
1164
1161
self .assert_eq (kdf , pdf )
1165
1162
1166
- # TODO: matching the behavior with pandas 1.2 and uncomment below test
1167
- # with self.assertRaisesRegex(
1168
- # ValueError,
1169
- # "shape mismatch: value array of shape (3,) could not be broadcast to indexing "
1170
- # "result of shape (1,)",
1171
- # ):
1172
- # kdf.iloc[[0], 1] = 10 * another_kdf.max_speed
1163
+ with self .assertRaisesRegex (ValueError , "shape mismatch" ):
1164
+ kdf .iloc [[0 ], 1 ] = 10 * another_kdf .max_speed
1173
1165
1174
1166
def test_series_loc_setitem (self ):
1175
1167
pdf = pd .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [4 , 5 , 6 ]}, index = ["cobra" , "viper" , "sidewinder" ])
@@ -1269,36 +1261,35 @@ def test_series_iloc_setitem(self):
1269
1261
self .assert_eq (kdf , pdf )
1270
1262
self .assert_eq (ksery , psery )
1271
1263
1272
- # TODO: matching the behavior with pandas 1.2 and uncomment below test.
1273
- # with self.assertRaisesRegex(
1274
- # ValueError,
1275
- # "cannot set using a list-like indexer with a different length than the value",
1276
- # ):
1277
- # kser.iloc[[1, 2]] = -kser_another
1264
+ with self .assertRaisesRegex (
1265
+ ValueError ,
1266
+ "cannot set using a list-like indexer with a different length than the value" ,
1267
+ ):
1268
+ kser .iloc [[1 , 2 ]] = - kser_another
1278
1269
1279
1270
kser .iloc [[0 , 1 , 2 ]] = 10 * kser_another
1280
1271
pser .iloc [[0 , 1 , 2 ]] = 10 * pser_another
1281
1272
self .assert_eq (kser , pser )
1282
1273
self .assert_eq (kdf , pdf )
1283
1274
self .assert_eq (ksery , psery )
1284
1275
1285
- # with self.assertRaisesRegex(
1286
- # ValueError,
1287
- # "cannot set using a list-like indexer with a different length than the value",
1288
- # ):
1289
- # kser.iloc[[0]] = 10 * kser_another
1276
+ with self .assertRaisesRegex (
1277
+ ValueError ,
1278
+ "cannot set using a list-like indexer with a different length than the value" ,
1279
+ ):
1280
+ kser .iloc [[0 ]] = 10 * kser_another
1290
1281
1291
1282
kser1 .iloc [[0 , 1 , 2 ]] = - kser_another
1292
1283
pser1 .iloc [[0 , 1 , 2 ]] = - pser_another
1293
1284
self .assert_eq (kser1 , pser1 )
1294
1285
self .assert_eq (kdf , pdf )
1295
1286
self .assert_eq (ksery , psery )
1296
1287
1297
- # with self.assertRaisesRegex(
1298
- # ValueError,
1299
- # "cannot set using a list-like indexer with a different length than the value",
1300
- # ):
1301
- # kser1.iloc[[1, 2]] = -kser_another
1288
+ with self .assertRaisesRegex (
1289
+ ValueError ,
1290
+ "cannot set using a list-like indexer with a different length than the value" ,
1291
+ ):
1292
+ kser1 .iloc [[1 , 2 ]] = - kser_another
1302
1293
1303
1294
pdf = pd .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [4 , 5 , 6 ]}, index = ["cobra" , "viper" , "sidewinder" ])
1304
1295
kdf = ps .from_pandas (pdf )
@@ -1317,24 +1308,23 @@ def test_series_iloc_setitem(self):
1317
1308
self .assert_eq (kdf , pdf )
1318
1309
self .assert_eq (ksery , psery )
1319
1310
1320
- # TODO: matching the behavior with pandas 1.2 and uncomment below test.
1321
- # with self.assertRaisesRegex(
1322
- # ValueError,
1323
- # "cannot set using a list-like indexer with a different length than the value",
1324
- # ):
1325
- # kiloc[[1, 2]] = -kser_another
1311
+ with self .assertRaisesRegex (
1312
+ ValueError ,
1313
+ "cannot set using a list-like indexer with a different length than the value" ,
1314
+ ):
1315
+ kiloc [[1 , 2 ]] = - kser_another
1326
1316
1327
1317
kiloc [[0 , 1 , 2 ]] = 10 * kser_another
1328
1318
piloc [[0 , 1 , 2 ]] = 10 * pser_another
1329
1319
self .assert_eq (kser , pser )
1330
1320
self .assert_eq (kdf , pdf )
1331
1321
self .assert_eq (ksery , psery )
1332
1322
1333
- # with self.assertRaisesRegex(
1334
- # ValueError,
1335
- # "cannot set using a list-like indexer with a different length than the value",
1336
- # ):
1337
- # kiloc[[0]] = 10 * kser_another
1323
+ with self .assertRaisesRegex (
1324
+ ValueError ,
1325
+ "cannot set using a list-like indexer with a different length than the value" ,
1326
+ ):
1327
+ kiloc [[0 ]] = 10 * kser_another
1338
1328
1339
1329
def test_update (self ):
1340
1330
pdf = pd .DataFrame ({"x" : [1 , 2 , 3 ], "y" : [10 , 20 , 30 ]})
@@ -1863,7 +1853,7 @@ def test_frame_iloc_setitem(self):
1863
1853
another_kdf = ps .DataFrame (pdf )
1864
1854
1865
1855
with self .assertRaisesRegex (ValueError , "Cannot combine the series or dataframe" ):
1866
- kdf .iloc [[1 , 2 ], [1 ]] = another_kdf .max_speed
1856
+ kdf .iloc [[1 , 2 ], [1 ]] = another_kdf .max_speed . iloc [[ 1 , 2 ]]
1867
1857
1868
1858
def test_series_loc_setitem (self ):
1869
1859
pser = pd .Series ([1 , 2 , 3 ], index = ["cobra" , "viper" , "sidewinder" ])
@@ -1889,7 +1879,7 @@ def test_series_iloc_setitem(self):
1889
1879
kser_another = ps .from_pandas (pser_another )
1890
1880
1891
1881
with self .assertRaisesRegex (ValueError , "Cannot combine the series or dataframe" ):
1892
- kser .iloc [[1 ]] = - kser_another
1882
+ kser .iloc [[1 ]] = - kser_another . iloc [[ 1 ]]
1893
1883
1894
1884
def test_where (self ):
1895
1885
pdf1 = pd .DataFrame ({"A" : [0 , 1 , 2 , 3 , 4 ], "B" : [100 , 200 , 300 , 400 , 500 ]})
0 commit comments