From b71a1bc791aced8bc6b364d751293f736bc0a317 Mon Sep 17 00:00:00 2001 From: Pavel Kirilin Date: Thu, 31 Oct 2024 17:14:37 +0100 Subject: [PATCH] Fixed floats cast issue. --- .github/workflows/test.yaml | 2 +- .python-version | 1 + python/tests/test_bindings.py | 17 +++++++++++++++++ src/utils.rs | 2 +- tox.ini | 2 ++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 03e9b20..b5cb474 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -64,7 +64,7 @@ jobs: - 9042:9042 strategy: matrix: - py_version: ["3.8", "3.9", "3.10", "3.11"] + py_version: ["3.8", "3.9", "3.10", "3.11", "3.12"] job: - os: ubuntu-latest ssl_cmd: sudo apt-get update && sudo apt-get install libssl-dev openssl diff --git a/.python-version b/.python-version index 0b1e0c8..4a448d5 100644 --- a/.python-version +++ b/.python-version @@ -1,3 +1,4 @@ +3.12.2 3.11.4 3.10.12 3.9.17 diff --git a/python/tests/test_bindings.py b/python/tests/test_bindings.py index 87f0b18..a6e1a07 100644 --- a/python/tests/test_bindings.py +++ b/python/tests/test_bindings.py @@ -108,6 +108,23 @@ async def test_named_parameters(scylla: Scylla) -> None: assert res.first() == to_insert +@pytest.mark.anyio +async def test_floats(scylla: Scylla) -> None: + table_name = random_string(4) + my_float = 1.234 + await scylla.execute( + f"CREATE TABLE {table_name} (id INT, fl FLOAT, PRIMARY KEY (id))", + ) + insert_query = f"INSERT INTO {table_name}(id, fl) VALUES (?, ?)" + + await scylla.execute(insert_query, [1, my_float]) + + res = await scylla.execute(f"SELECT fl FROM {table_name}") + scalar = res.scalar() + assert scalar + assert abs(scalar - my_float) < 0.001 + + @pytest.mark.anyio async def test_timestamps(scylla: Scylla) -> None: table_name = random_string(4) diff --git a/src/utils.rs b/src/utils.rs index 2cff220..f5ce637 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -369,7 +369,7 @@ pub fn cql_to_py<'a>( .ok_or(ScyllaPyError::ValueDowncastError(col_name.into(), "Double")) .map(|val| val.to_object(py).into_ref(py)), ColumnType::Float => unwrapped_value - .as_double() + .as_float() .ok_or(ScyllaPyError::ValueDowncastError(col_name.into(), "Float")) .map(|val| val.to_object(py).into_ref(py)), ColumnType::Int => unwrapped_value diff --git a/tox.ini b/tox.ini index d661bf3..93a444b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,7 @@ [tox] isolated_build = true env_list = + py312 py311 py310 py39 @@ -8,6 +9,7 @@ env_list = [gh] python = + 3.12 = py312 3.11 = py311 3.10 = py310 3.9 = py39