From e2feeaee9d37be38da852a207f365d33ba4036ca Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Wed, 3 Jul 2024 10:31:48 +0200 Subject: [PATCH] test(python): Avoid use of `np.trapz` in tests to prepare for NumPy 2.0 (#17387) --- py-polars/tests/unit/operations/map/test_map_batches.py | 2 +- py-polars/tests/unit/operations/map/test_map_groups.py | 6 ++---- py-polars/tests/unit/test_errors.py | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/py-polars/tests/unit/operations/map/test_map_batches.py b/py-polars/tests/unit/operations/map/test_map_batches.py index ab59c4fad304..0714fa2ed404 100644 --- a/py-polars/tests/unit/operations/map/test_map_batches.py +++ b/py-polars/tests/unit/operations/map/test_map_batches.py @@ -41,7 +41,7 @@ def test_error_on_reducing_map() -> None: r"the input length \(6\); consider using `apply` instead" ), ): - df.group_by("id").agg(pl.map_batches(["t", "y"], np.trapz)) + df.group_by("id").agg(pl.map_batches(["t", "y"], np.mean)) df = pl.DataFrame({"x": [1, 2, 3, 4], "group": [1, 2, 1, 2]}) diff --git a/py-polars/tests/unit/operations/map/test_map_groups.py b/py-polars/tests/unit/operations/map/test_map_groups.py index fdfe667b712b..e8f5554333b1 100644 --- a/py-polars/tests/unit/operations/map/test_map_groups.py +++ b/py-polars/tests/unit/operations/map/test_map_groups.py @@ -141,10 +141,8 @@ def test_map_groups_numpy_output_3057() -> None: ) result = df.group_by("id", maintain_order=True).agg( - pl.map_groups(["y", "t"], lambda lst: np.trapz(y=lst[0], x=lst[1])).alias( - "result" - ) + pl.map_groups(["y", "t"], lambda lst: np.mean([lst[0], lst[1]])).alias("result") ) - expected = pl.DataFrame({"id": [0, 1], "result": [1.955, 13.0]}) + expected = pl.DataFrame({"id": [0, 1], "result": [2.266666, 7.333333]}) assert_frame_equal(result, expected) diff --git a/py-polars/tests/unit/test_errors.py b/py-polars/tests/unit/test_errors.py index 471718b7b4af..2192e68a1840 100644 --- a/py-polars/tests/unit/test_errors.py +++ b/py-polars/tests/unit/test_errors.py @@ -45,7 +45,7 @@ def test_error_on_reducing_map() -> None: r"the input length \(6\); consider using `apply` instead" ), ): - df.group_by("id").agg(pl.map_batches(["t", "y"], np.trapz)) + df.group_by("id").agg(pl.map_batches(["t", "y"], np.mean)) df = pl.DataFrame({"x": [1, 2, 3, 4], "group": [1, 2, 1, 2]}) with pytest.raises(