@@ -465,8 +465,6 @@ def test_multi_func(df):
465
465
col2 = df ["B" ]
466
466
467
467
grouped = df .groupby ([col1 .get , col2 .get ])
468
- with pytest .raises (TypeError , match = "Could not convert" ):
469
- grouped .mean ()
470
468
agged = grouped .mean (numeric_only = True )
471
469
expected = df .groupby (["A" , "B" ]).mean ()
472
470
@@ -665,17 +663,11 @@ def test_groupby_as_index_agg(df):
665
663
666
664
# single-key
667
665
668
- with pytest .raises (TypeError , match = "Could not convert" ):
669
- grouped .agg (np .mean )
670
666
result = grouped [["C" , "D" ]].agg (np .mean )
671
- with pytest .raises (TypeError , match = "Could not convert" ):
672
- grouped .mean ()
673
667
expected = grouped .mean (numeric_only = True )
674
668
tm .assert_frame_equal (result , expected )
675
669
676
670
result2 = grouped .agg ({"C" : np .mean , "D" : np .sum })
677
- with pytest .raises (TypeError , match = "Could not convert" ):
678
- grouped .mean ()
679
671
expected2 = grouped .mean (numeric_only = True )
680
672
expected2 ["D" ] = grouped .sum ()["D" ]
681
673
tm .assert_frame_equal (result2 , expected2 )
@@ -793,11 +785,7 @@ def test_groupby_as_index_cython(df):
793
785
794
786
# single-key
795
787
grouped = data .groupby ("A" , as_index = False )
796
- with pytest .raises (TypeError , match = "Could not convert" ):
797
- grouped .mean ()
798
788
result = grouped .mean (numeric_only = True )
799
- with pytest .raises (TypeError , match = "Could not convert" ):
800
- data .groupby (["A" ]).mean ()
801
789
expected = data .groupby (["A" ]).mean (numeric_only = True )
802
790
expected .insert (0 , "A" , expected .index )
803
791
expected .index = RangeIndex (len (expected ))
@@ -960,11 +948,7 @@ def test_empty_groups_corner(mframe):
960
948
)
961
949
962
950
grouped = df .groupby (["k1" , "k2" ])
963
- with pytest .raises (TypeError , match = "Could not convert" ):
964
- grouped .agg (np .mean )
965
951
result = grouped [["v1" , "v2" ]].agg (np .mean )
966
- with pytest .raises (TypeError , match = "Could not convert" ):
967
- grouped .mean ()
968
952
expected = grouped .mean (numeric_only = True )
969
953
tm .assert_frame_equal (result , expected )
970
954
@@ -1148,8 +1132,6 @@ def test_groupby_with_hier_columns():
1148
1132
# add a nuisance column
1149
1133
sorted_columns , _ = columns .sortlevel (0 )
1150
1134
df ["A" , "foo" ] = "bar"
1151
- with pytest .raises (TypeError , match = "Could not convert" ):
1152
- df .groupby (level = 0 ).mean ()
1153
1135
result = df .groupby (level = 0 ).mean (numeric_only = True )
1154
1136
tm .assert_index_equal (result .columns , df .columns [:- 1 ])
1155
1137
@@ -1183,11 +1165,7 @@ def test_groupby_wrong_multi_labels():
1183
1165
1184
1166
1185
1167
def test_groupby_series_with_name (df ):
1186
- with pytest .raises (TypeError , match = "Could not convert" ):
1187
- df .groupby (df ["A" ]).mean ()
1188
1168
result = df .groupby (df ["A" ]).mean (numeric_only = True )
1189
- with pytest .raises (TypeError , match = "Could not convert" ):
1190
- df .groupby (df ["A" ], as_index = False ).mean ()
1191
1169
result2 = df .groupby (df ["A" ], as_index = False ).mean (numeric_only = True )
1192
1170
assert result .index .name == "A"
1193
1171
assert "A" in result2
@@ -1337,11 +1315,7 @@ def test_groupby_unit64_float_conversion():
1337
1315
1338
1316
1339
1317
def test_groupby_list_infer_array_like (df ):
1340
- with pytest .raises (TypeError , match = "Could not convert" ):
1341
- df .groupby (list (df ["A" ])).mean ()
1342
1318
result = df .groupby (list (df ["A" ])).mean (numeric_only = True )
1343
- with pytest .raises (TypeError , match = "Could not convert" ):
1344
- df .groupby (df ["A" ]).mean ()
1345
1319
expected = df .groupby (df ["A" ]).mean (numeric_only = True )
1346
1320
tm .assert_frame_equal (result , expected , check_names = False )
1347
1321
@@ -1455,8 +1429,6 @@ def test_groupby_2d_malformed():
1455
1429
d ["zeros" ] = [0 , 0 ]
1456
1430
d ["ones" ] = [1 , 1 ]
1457
1431
d ["label" ] = ["l1" , "l2" ]
1458
- with pytest .raises (TypeError , match = "Could not convert" ):
1459
- d .groupby (["group" ]).mean ()
1460
1432
tmp = d .groupby (["group" ]).mean (numeric_only = True )
1461
1433
res_values = np .array ([[0.0 , 1.0 ], [0.0 , 1.0 ]])
1462
1434
tm .assert_index_equal (tmp .columns , Index (["zeros" , "ones" ]))
0 commit comments