Skip to content

Commit

Permalink
Fixed floats cast issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rius committed Oct 31, 2024
1 parent d8d01c1 commit b71a1bc
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
3.12.2
3.11.4
3.10.12
3.9.17
Expand Down
17 changes: 17 additions & 0 deletions python/tests/test_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
[tox]
isolated_build = true
env_list =
py312
py311
py310
py39
py38

[gh]
python =
3.12 = py312
3.11 = py311
3.10 = py310
3.9 = py39
Expand Down

0 comments on commit b71a1bc

Please sign in to comment.