-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add full coverage of utility functions (#15995)
The datetime conversion tests just test that we can round-trip correctly for now. Authors: - Lawrence Mitchell (https://github.com/wence-) Approvers: - Thomas Li (https://github.com/lithomas1) - Kyle Edwards (https://github.com/KyleFromNVIDIA) URL: #15995
- Loading branch information
Showing
6 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
python/cudf_polars/tests/expressions/test_datetime_basic.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
import polars as pl | ||
|
||
from cudf_polars.testing.asserts import assert_gpu_result_equal | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"dtype", | ||
[ | ||
pl.Date(), | ||
pl.Datetime("ms"), | ||
pl.Datetime("us"), | ||
pl.Datetime("ns"), | ||
pl.Duration("ms"), | ||
pl.Duration("us"), | ||
pl.Duration("ns"), | ||
], | ||
ids=repr, | ||
) | ||
def test_datetime_dataframe_scan(dtype): | ||
ldf = pl.DataFrame( | ||
{ | ||
"a": pl.Series([1, 2, 3, 4, 5, 6, 7], dtype=dtype), | ||
"b": pl.Series([3, 4, 5, 6, 7, 8, 9], dtype=pl.UInt16), | ||
} | ||
).lazy() | ||
|
||
query = ldf.select(pl.col("b"), pl.col("a")) | ||
assert_gpu_result_equal(query) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
import polars as pl | ||
|
||
from cudf_polars.utils.dtypes import from_polars | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"pltype", | ||
[ | ||
pl.Time(), | ||
pl.Struct({"a": pl.Int8, "b": pl.Float32}), | ||
pl.Datetime("ms", time_zone="US/Pacific"), | ||
pl.Array(pl.Int8, 2), | ||
pl.Binary(), | ||
pl.Categorical(), | ||
pl.Enum(["a", "b"]), | ||
pl.Field("a", pl.Int8), | ||
pl.Object(), | ||
pl.Unknown(), | ||
], | ||
ids=repr, | ||
) | ||
def test_unhandled_dtype_conversion_raises(pltype): | ||
with pytest.raises(NotImplementedError): | ||
_ = from_polars(pltype) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from cudf_polars.utils.sorting import sort_order | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"descending,nulls_last,num_keys", | ||
[ | ||
([True], [False, True], 3), | ||
([True, True], [False, True, False], 3), | ||
([False, True], [True], 3), | ||
], | ||
) | ||
def test_sort_order_raises_mismatch(descending, nulls_last, num_keys): | ||
with pytest.raises(ValueError): | ||
_ = sort_order(descending, nulls_last=nulls_last, num_keys=num_keys) |