@@ -562,11 +562,9 @@ def test_apply_dict(self):
562
562
563
563
# GH 8735
564
564
A = DataFrame ([["foo" , "bar" ], ["spam" , "eggs" ]])
565
- A_dicts = Series (
566
- [dict ([(0 , "foo" ), (1 , "spam" )]), dict ([(0 , "bar" ), (1 , "eggs" )])]
567
- )
565
+ A_dicts = Series ([{0 : "foo" , 1 : "spam" }, {0 : "bar" , 1 : "eggs" }])
568
566
B = DataFrame ([[0 , 1 ], [2 , 3 ]])
569
- B_dicts = Series ([dict ([( 0 , 0 ), ( 1 , 2 )]), dict ([( 0 , 1 ), ( 1 , 3 )]) ])
567
+ B_dicts = Series ([{ 0 : 0 , 1 : 2 }, { 0 : 1 , 1 : 3 } ])
570
568
fn = lambda x : x .to_dict ()
571
569
572
570
for df , dicts in [(A , A_dicts ), (B , B_dicts )]:
@@ -1221,7 +1219,7 @@ def test_agg_reduce(self, axis, float_frame):
1221
1219
tm .assert_frame_equal (result , expected )
1222
1220
1223
1221
# dict input with scalars
1224
- func = dict ([( name1 , "mean" ), ( name2 , "sum" )])
1222
+ func = { name1 : "mean" , name2 : "sum" }
1225
1223
result = float_frame .agg (func , axis = axis )
1226
1224
expected = Series (
1227
1225
[
@@ -1233,7 +1231,7 @@ def test_agg_reduce(self, axis, float_frame):
1233
1231
tm .assert_series_equal (result , expected )
1234
1232
1235
1233
# dict input with lists
1236
- func = dict ([( name1 , ["mean" ]), ( name2 , ["sum" ])])
1234
+ func = { name1 : ["mean" ], name2 : ["sum" ]}
1237
1235
result = float_frame .agg (func , axis = axis )
1238
1236
expected = DataFrame (
1239
1237
{
@@ -1249,33 +1247,25 @@ def test_agg_reduce(self, axis, float_frame):
1249
1247
tm .assert_frame_equal (result , expected )
1250
1248
1251
1249
# dict input with lists with multiple
1252
- func = dict ([( name1 , ["mean" , "sum" ]), ( name2 , ["sum" , "max" ])])
1250
+ func = { name1 : ["mean" , "sum" ], name2 : ["sum" , "max" ]}
1253
1251
result = float_frame .agg (func , axis = axis )
1254
1252
expected = pd .concat (
1255
- dict (
1256
- [
1257
- (
1258
- name1 ,
1259
- Series (
1260
- [
1261
- float_frame .loc (other_axis )[name1 ].mean (),
1262
- float_frame .loc (other_axis )[name1 ].sum (),
1263
- ],
1264
- index = ["mean" , "sum" ],
1265
- ),
1266
- ),
1267
- (
1268
- name2 ,
1269
- Series (
1270
- [
1271
- float_frame .loc (other_axis )[name2 ].sum (),
1272
- float_frame .loc (other_axis )[name2 ].max (),
1273
- ],
1274
- index = ["sum" , "max" ],
1275
- ),
1276
- ),
1277
- ]
1278
- ),
1253
+ {
1254
+ name1 : Series (
1255
+ [
1256
+ float_frame .loc (other_axis )[name1 ].mean (),
1257
+ float_frame .loc (other_axis )[name1 ].sum (),
1258
+ ],
1259
+ index = ["mean" , "sum" ],
1260
+ ),
1261
+ name2 : Series (
1262
+ [
1263
+ float_frame .loc (other_axis )[name2 ].sum (),
1264
+ float_frame .loc (other_axis )[name2 ].max (),
1265
+ ],
1266
+ index = ["sum" , "max" ],
1267
+ ),
1268
+ },
1279
1269
axis = 1 ,
1280
1270
)
1281
1271
expected = expected .T if axis in {1 , "columns" } else expected
0 commit comments