-
Notifications
You must be signed in to change notification settings - Fork 928
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
pylibcudf.Scalar.from_py
for construction from Python strings, …
…bool, int, float (#17898) Towards #17054 Authors: - Matthew Roeschke (https://github.com/mroeschke) - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Matthew Murray (https://github.com/Matt711) - Vyas Ramasubramani (https://github.com/vyasr) URL: #17898
- Loading branch information
Showing
3 changed files
with
125 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright (c) 2024-2025, NVIDIA CORPORATION. | ||
import datetime | ||
|
||
import pyarrow as pa | ||
import pytest | ||
|
||
import pylibcudf as plc | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"val", [True, False, -1, 0, 1 - 1.0, 0.0, 1.52, "", "a1!"] | ||
) | ||
def test_from_py(val): | ||
result = plc.Scalar.from_py(val) | ||
expected = pa.scalar(val) | ||
assert plc.interop.to_arrow(result).equals(expected) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"val", [datetime.datetime(2020, 1, 1), datetime.timedelta(1), [1], {1: 1}] | ||
) | ||
def test_from_py_notimplemented(val): | ||
with pytest.raises(NotImplementedError): | ||
plc.Scalar.from_py(val) | ||
|
||
|
||
@pytest.mark.parametrize("val", [object, None]) | ||
def test_from_py_typeerror(val): | ||
with pytest.raises(TypeError): | ||
plc.Scalar.from_py(val) |