|
14 | 14 | Series,
|
15 | 15 | Timestamp,
|
16 | 16 | date_range,
|
17 |
| - notna, |
18 | 17 | )
|
19 | 18 | import pandas._testing as tm
|
20 |
| -from pandas.core.base import SpecificationError |
21 | 19 | from pandas.tests.frame.common import zip_frames
|
22 | 20 |
|
23 | 21 |
|
24 |
| -@pytest.fixture |
25 |
| -def int_frame_const_col(): |
26 |
| - """ |
27 |
| - Fixture for DataFrame of ints which are constant per column |
28 |
| -
|
29 |
| - Columns are ['A', 'B', 'C'], with values (per column): [1, 2, 3] |
30 |
| - """ |
31 |
| - df = DataFrame( |
32 |
| - np.tile(np.arange(3, dtype="int64"), 6).reshape(6, -1) + 1, |
33 |
| - columns=["A", "B", "C"], |
34 |
| - ) |
35 |
| - return df |
36 |
| - |
37 |
| - |
38 | 22 | def test_apply(float_frame):
|
39 | 23 | with np.errstate(all="ignore"):
|
40 | 24 | # ufunc
|
@@ -195,17 +179,6 @@ def test_apply_with_string_funcs(request, float_frame, func, args, kwds, how):
|
195 | 179 | tm.assert_series_equal(result, expected)
|
196 | 180 |
|
197 | 181 |
|
198 |
| -@pytest.mark.parametrize( |
199 |
| - "how, args", [("pct_change", ()), ("nsmallest", (1, ["a", "b"])), ("tail", 1)] |
200 |
| -) |
201 |
| -def test_apply_str_axis_1_raises(how, args): |
202 |
| - # GH 39211 - some ops don't support axis=1 |
203 |
| - df = DataFrame({"a": [1, 2], "b": [3, 4]}) |
204 |
| - msg = f"Operation {how} does not support axis=1" |
205 |
| - with pytest.raises(ValueError, match=msg): |
206 |
| - df.apply(how, axis=1, args=args) |
207 |
| - |
208 |
| - |
209 | 182 | def test_apply_broadcast(float_frame, int_frame_const_col):
|
210 | 183 |
|
211 | 184 | # scalars
|
@@ -259,27 +232,6 @@ def test_apply_broadcast(float_frame, int_frame_const_col):
|
259 | 232 | tm.assert_frame_equal(result, expected)
|
260 | 233 |
|
261 | 234 |
|
262 |
| -def test_apply_broadcast_error(int_frame_const_col): |
263 |
| - df = int_frame_const_col |
264 |
| - |
265 |
| - # > 1 ndim |
266 |
| - msg = "too many dims to broadcast" |
267 |
| - with pytest.raises(ValueError, match=msg): |
268 |
| - df.apply( |
269 |
| - lambda x: np.array([1, 2]).reshape(-1, 2), |
270 |
| - axis=1, |
271 |
| - result_type="broadcast", |
272 |
| - ) |
273 |
| - |
274 |
| - # cannot broadcast |
275 |
| - msg = "cannot broadcast result" |
276 |
| - with pytest.raises(ValueError, match=msg): |
277 |
| - df.apply(lambda x: [1, 2], axis=1, result_type="broadcast") |
278 |
| - |
279 |
| - with pytest.raises(ValueError, match=msg): |
280 |
| - df.apply(lambda x: Series([1, 2]), axis=1, result_type="broadcast") |
281 |
| - |
282 |
| - |
283 | 235 | def test_apply_raw(float_frame, mixed_type_frame):
|
284 | 236 | def _assert_raw(x):
|
285 | 237 | assert isinstance(x, np.ndarray)
|
@@ -425,71 +377,6 @@ def test_apply_differently_indexed():
|
425 | 377 | tm.assert_frame_equal(result, expected)
|
426 | 378 |
|
427 | 379 |
|
428 |
| -def test_apply_modify_traceback(): |
429 |
| - data = DataFrame( |
430 |
| - { |
431 |
| - "A": [ |
432 |
| - "foo", |
433 |
| - "foo", |
434 |
| - "foo", |
435 |
| - "foo", |
436 |
| - "bar", |
437 |
| - "bar", |
438 |
| - "bar", |
439 |
| - "bar", |
440 |
| - "foo", |
441 |
| - "foo", |
442 |
| - "foo", |
443 |
| - ], |
444 |
| - "B": [ |
445 |
| - "one", |
446 |
| - "one", |
447 |
| - "one", |
448 |
| - "two", |
449 |
| - "one", |
450 |
| - "one", |
451 |
| - "one", |
452 |
| - "two", |
453 |
| - "two", |
454 |
| - "two", |
455 |
| - "one", |
456 |
| - ], |
457 |
| - "C": [ |
458 |
| - "dull", |
459 |
| - "dull", |
460 |
| - "shiny", |
461 |
| - "dull", |
462 |
| - "dull", |
463 |
| - "shiny", |
464 |
| - "shiny", |
465 |
| - "dull", |
466 |
| - "shiny", |
467 |
| - "shiny", |
468 |
| - "shiny", |
469 |
| - ], |
470 |
| - "D": np.random.randn(11), |
471 |
| - "E": np.random.randn(11), |
472 |
| - "F": np.random.randn(11), |
473 |
| - } |
474 |
| - ) |
475 |
| - |
476 |
| - data.loc[4, "C"] = np.nan |
477 |
| - |
478 |
| - def transform(row): |
479 |
| - if row["C"].startswith("shin") and row["A"] == "foo": |
480 |
| - row["D"] = 7 |
481 |
| - return row |
482 |
| - |
483 |
| - def transform2(row): |
484 |
| - if notna(row["C"]) and row["C"].startswith("shin") and row["A"] == "foo": |
485 |
| - row["D"] = 7 |
486 |
| - return row |
487 |
| - |
488 |
| - msg = "'float' object has no attribute 'startswith'" |
489 |
| - with pytest.raises(AttributeError, match=msg): |
490 |
| - data.apply(transform, axis=1) |
491 |
| - |
492 |
| - |
493 | 380 | def test_apply_bug():
|
494 | 381 |
|
495 | 382 | # GH 6125
|
@@ -1105,19 +992,6 @@ def test_result_type(int_frame_const_col):
|
1105 | 992 | tm.assert_frame_equal(result, expected)
|
1106 | 993 |
|
1107 | 994 |
|
1108 |
| -@pytest.mark.parametrize("result_type", ["foo", 1]) |
1109 |
| -def test_result_type_error(result_type, int_frame_const_col): |
1110 |
| - # allowed result_type |
1111 |
| - df = int_frame_const_col |
1112 |
| - |
1113 |
| - msg = ( |
1114 |
| - "invalid value for result_type, must be one of " |
1115 |
| - "{None, 'reduce', 'broadcast', 'expand'}" |
1116 |
| - ) |
1117 |
| - with pytest.raises(ValueError, match=msg): |
1118 |
| - df.apply(lambda x: [1, 2, 3], axis=1, result_type=result_type) |
1119 |
| - |
1120 |
| - |
1121 | 995 | @pytest.mark.parametrize(
|
1122 | 996 | "box",
|
1123 | 997 | [lambda x: list(x), lambda x: tuple(x), lambda x: np.array(x, dtype="int64")],
|
@@ -1174,20 +1048,6 @@ def test_agg_transform(axis, float_frame):
|
1174 | 1048 | tm.assert_frame_equal(result, expected)
|
1175 | 1049 |
|
1176 | 1050 |
|
1177 |
| -def test_transform_and_agg_err(axis, float_frame): |
1178 |
| - # cannot both transform and agg |
1179 |
| - msg = "cannot combine transform and aggregation operations" |
1180 |
| - with pytest.raises(ValueError, match=msg): |
1181 |
| - with np.errstate(all="ignore"): |
1182 |
| - float_frame.agg(["max", "sqrt"], axis=axis) |
1183 |
| - |
1184 |
| - df = DataFrame({"A": range(5), "B": 5}) |
1185 |
| - |
1186 |
| - def f(): |
1187 |
| - with np.errstate(all="ignore"): |
1188 |
| - df.agg({"A": ["abs", "sum"], "B": ["mean", "max"]}, axis=axis) |
1189 |
| - |
1190 |
| - |
1191 | 1051 | def test_demo():
|
1192 | 1052 | # demonstration tests
|
1193 | 1053 | df = DataFrame({"A": range(5), "B": 5})
|
@@ -1258,16 +1118,6 @@ def test_agg_multiple_mixed_no_warning():
|
1258 | 1118 | tm.assert_frame_equal(result, expected)
|
1259 | 1119 |
|
1260 | 1120 |
|
1261 |
| -def test_agg_dict_nested_renaming_depr(): |
1262 |
| - |
1263 |
| - df = DataFrame({"A": range(5), "B": 5}) |
1264 |
| - |
1265 |
| - # nested renaming |
1266 |
| - msg = r"nested renamer is not supported" |
1267 |
| - with pytest.raises(SpecificationError, match=msg): |
1268 |
| - df.agg({"A": {"foo": "min"}, "B": {"bar": "max"}}) |
1269 |
| - |
1270 |
| - |
1271 | 1121 | def test_agg_reduce(axis, float_frame):
|
1272 | 1122 | other_axis = 1 if axis in {0, "index"} else 0
|
1273 | 1123 | name1, name2 = float_frame.axes[other_axis].unique()[:2].sort_values()
|
@@ -1520,19 +1370,6 @@ def test_agg_cython_table_transform(df, func, expected, axis):
|
1520 | 1370 | tm.assert_frame_equal(result, expected)
|
1521 | 1371 |
|
1522 | 1372 |
|
1523 |
| -@pytest.mark.parametrize( |
1524 |
| - "df, func, expected", |
1525 |
| - tm.get_cython_table_params( |
1526 |
| - DataFrame([["a", "b"], ["b", "a"]]), [["cumprod", TypeError]] |
1527 |
| - ), |
1528 |
| -) |
1529 |
| -def test_agg_cython_table_raises(df, func, expected, axis): |
1530 |
| - # GH 21224 |
1531 |
| - msg = "can't multiply sequence by non-int of type 'str'" |
1532 |
| - with pytest.raises(expected, match=msg): |
1533 |
| - df.agg(func, axis=axis) |
1534 |
| - |
1535 |
| - |
1536 | 1373 | @pytest.mark.parametrize("axis", [0, 1])
|
1537 | 1374 | @pytest.mark.parametrize(
|
1538 | 1375 | "args, kwargs",
|
|
0 commit comments