From 208d530bb6b8ce1ef4741ae92c7223015b7c5a17 Mon Sep 17 00:00:00 2001 From: Luke Manley Date: Fri, 27 Dec 2024 07:53:53 -0500 Subject: [PATCH] test: Add tests for `floor/ceil` on integers (#20479) --- py-polars/tests/unit/dataframe/test_df.py | 18 ++++++++++++++++-- .../tests/unit/lazyframe/test_lazyframe.py | 19 +++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/py-polars/tests/unit/dataframe/test_df.py b/py-polars/tests/unit/dataframe/test_df.py index 9cac26d1e7d..3649d60a629 100644 --- a/py-polars/tests/unit/dataframe/test_df.py +++ b/py-polars/tests/unit/dataframe/test_df.py @@ -2790,10 +2790,24 @@ def test_deadlocks_3409() -> None: ) == {"col1": [0, 0, 0]} +def test_ceil() -> None: + df = pl.DataFrame({"a": [1.8, 1.2, 3.0]}) + result = df.select(pl.col("a").ceil()) + assert_frame_equal(result, pl.DataFrame({"a": [2.0, 2.0, 3.0]})) + + df = pl.DataFrame({"a": [1, 2, 3]}) + result = df.select(pl.col("a").ceil()) + assert_frame_equal(df, result) + + def test_floor() -> None: df = pl.DataFrame({"a": [1.8, 1.2, 3.0]}) - col_a_floor = df.select(pl.col("a").floor())["a"] - assert_series_equal(col_a_floor, pl.Series("a", [1, 1, 3]).cast(pl.Float64)) + result = df.select(pl.col("a").floor()) + assert_frame_equal(result, pl.DataFrame({"a": [1.0, 1.0, 3.0]})) + + df = pl.DataFrame({"a": [1, 2, 3]}) + result = df.select(pl.col("a").floor()) + assert_frame_equal(df, result) def test_floor_divide() -> None: diff --git a/py-polars/tests/unit/lazyframe/test_lazyframe.py b/py-polars/tests/unit/lazyframe/test_lazyframe.py index 5ef0b65deba..38f89ff8785 100644 --- a/py-polars/tests/unit/lazyframe/test_lazyframe.py +++ b/py-polars/tests/unit/lazyframe/test_lazyframe.py @@ -504,9 +504,24 @@ def test_cum_agg() -> None: ) +def test_ceil() -> None: + ldf = pl.LazyFrame({"a": [1.8, 1.2, 3.0]}) + result = ldf.select(pl.col("a").ceil()).collect() + assert_frame_equal(result, pl.DataFrame({"a": [2.0, 2.0, 3.0]})) + + ldf = pl.LazyFrame({"a": [1, 2, 3]}) + result = ldf.select(pl.col("a").ceil()).collect() + assert_frame_equal(ldf.collect(), result) + + def test_floor() -> None: - ldf = pl.LazyFrame({"a": [1.8, 1.2, 3.0]}).select(pl.col("a").floor()) - assert_series_equal(ldf.collect()["a"], pl.Series("a", [1, 1, 3]).cast(pl.Float64)) + ldf = pl.LazyFrame({"a": [1.8, 1.2, 3.0]}) + result = ldf.select(pl.col("a").floor()).collect() + assert_frame_equal(result, pl.DataFrame({"a": [1.0, 1.0, 3.0]})) + + ldf = pl.LazyFrame({"a": [1, 2, 3]}) + result = ldf.select(pl.col("a").floor()).collect() + assert_frame_equal(ldf.collect(), result) @pytest.mark.parametrize(