From b31a67e9658acba60e14c64f78e2ebd8469d49ac Mon Sep 17 00:00:00 2001 From: Tam Nguyen Duc <1218621+tamnd@users.noreply.github.com> Date: Tue, 25 Aug 2026 13:39:09 +0700 Subject: [PATCH 1/5] An exact decimal is a decimal.Decimal The engine grew a decimal at ABI 0.15: an i128 of unscaled units and a scale, reachable today through CAST('1.20' AS DECIMAL(5, 2)). Python already has the type for it, so this hands one over as a decimal.Decimal and takes one back as a parameter. Not a float, which is the whole reason the engine has the type. A tenth is not a binary fraction, and a price read into a float is not the price. Built from the engine's own spelling rather than from the digits and the scale, because Decimal("1.20") is the one constructor exact for both, and read back through format(d, "f") rather than str(d), because Python prints some decimals with an exponent and Decimal("1E+2") is a hundred at no places rather than a one at two of them. A parameter that is not an exact number is refused at the call and says which: a NaN or an infinity is not a number the engine holds, thirty eight digits is the widest DECIMAL(p, s) takes, and a scale past that is a point further right than a column could declare. Failing there is the point, since a decimal that quietly became a float would be a query comparing a price against something that is not it. The type check runs before the integer and the float arms, since a Decimal is neither and would otherwise go through extract::, which is the loss the caller picked the type to avoid. NUMBER in the DB-API module now covers it, because PEP 249 puts every numeric column under NUMBER and a decimal is one. The conformance runner learned to print and compare decimals with the scale as well as the number, since two decimals of one number at two scales are equal to Python and print differently. DECIMAL stays a reserved name a case may not write, matching the reference runner. --- Cargo.toml | 6 +-- README.md | 1 + conformance/values.py | 17 +++++++ python/zudb/dbapi.py | 7 ++- python/zudb/types.py | 6 ++- src/value.rs | 83 +++++++++++++++++++++++++++++++++- tests/test_values.py | 101 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 215 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8b214e8..10dbe10 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,14 +18,14 @@ crate-type = ["cdylib"] # with (ADR 0002), so a revision is the honest way to say which one. # A local checkout is used instead with a `paths` override in # `.cargo/config.toml`, which is untracked on purpose. -zudb = { package = "zu", git = "https://github.com/tamnd/zu", rev = "9dcb7b42b50f3a802cae62b18d9e99f30efefad1" } -zu-common = { git = "https://github.com/tamnd/zu", rev = "9dcb7b42b50f3a802cae62b18d9e99f30efefad1" } +zudb = { package = "zu", git = "https://github.com/tamnd/zu", rev = "cfdc70f291719309b96a8300dc8425154d0fd5d5" } +zu-common = { git = "https://github.com/tamnd/zu", rev = "cfdc70f291719309b96a8300dc8425154d0fd5d5" } # The one translation from a result into Arrow, which lives in the # engine tree so that every client agrees about what a column becomes. # `ffi` is the only feature this client turns on: what Python wants is # the C Data Interface, which is how a result reaches pyarrow, pandas # and polars without a Python object per cell. -zu-arrow = { git = "https://github.com/tamnd/zu", rev = "9dcb7b42b50f3a802cae62b18d9e99f30efefad1", features = ["ffi"] } +zu-arrow = { git = "https://github.com/tamnd/zu", rev = "cfdc70f291719309b96a8300dc8425154d0fd5d5", features = ["ffi"] } # `extension-module` is asked for by maturin, in pyproject.toml, and # not here. Only the build backend knows how an extension is linked on # the platform it is building for, and a crate that turns the feature diff --git a/README.md b/README.md index 39bf8cb..d886a1d 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ The interesting parts: - **Complete `.pyi` stubs inside the wheel**, checked against the runtime in CI, so mypy and pyright and your editor all work with no extra install. - **`import zudb` costs about 4 ms** on this machine and is gated at 50, and pandas, polars and pyarrow are imported when you ask for one and not before. Importing pandas costs 700 ms, which is most of why none of them is a dependency. - **Graph values are real classes.** `Node`, `Rel`, and `Path` have `.labels`, `.id`, `.properties`, and an HTML repr. Not dicts, because a dict cannot tell a property named `labels` apart from the label set. +- **An exact decimal is a `decimal.Decimal`.** `CAST('1.20' AS DECIMAL(5, 2))` comes back with both places, and one goes in as a parameter the same way. Not a `float`, because a tenth is not a binary fraction and a price held as one is not the price. ## A database with no file diff --git a/conformance/values.py b/conformance/values.py index 060acef..625bbd5 100644 --- a/conformance/values.py +++ b/conformance/values.py @@ -35,6 +35,7 @@ from __future__ import annotations import datetime +import decimal import math from dataclasses import dataclass @@ -660,6 +661,13 @@ def same(want: object, got: object) -> bool: if math.isnan(want) and math.isnan(got): return True return math.copysign(1.0, want) == math.copysign(1.0, got) and want == got + # Two decimals of one number at two scales are equal to Python and + # print differently, and what a case asserts is what a reader would + # see, so the scale is compared as well. It has no case to read yet, + # since DECIMAL is a reserved name, and the rule is written where the + # reference writes it rather than left for the first one to discover. + if isinstance(want, decimal.Decimal) and isinstance(got, decimal.Decimal): + return want.as_tuple().exponent == got.as_tuple().exponent and want == got if isinstance(want, list) and isinstance(got, list): return len(want) == len(got) and all(same(a, b) for a, b in zip(want, got, strict=True)) if isinstance(want, Walk) and isinstance(got, Walk): @@ -681,6 +689,15 @@ def show(value: object) -> str: return f'INT64 "{value}"' if isinstance(value, float): return f'FLOAT64 "{_show_float(value)}"' + # A decimal is a value a statement can hand back today even though + # DECIMAL is still a reserved name a case may not write, since CAST + # reaches one and no case declares one. That makes this the got side + # of a report and never the want side, and a report that could not + # print what it got would be the least useful moment to find out. + # Formatted rather than str()'d because Python prints some decimals + # with an exponent and the reference runner never does. + if isinstance(value, decimal.Decimal): + return f'DECIMAL "{format(value, "f")}"' if isinstance(value, str): return f"STRING {quote(value)}" # Upper case because ISO writes the literal that way, and a report diff --git a/python/zudb/dbapi.py b/python/zudb/dbapi.py index 9140a2f..c1a891e 100644 --- a/python/zudb/dbapi.py +++ b/python/zudb/dbapi.py @@ -42,6 +42,7 @@ import contextlib import datetime +import decimal import os import time from collections import deque @@ -298,7 +299,11 @@ def __repr__(self) -> str: STRING = _Type("STRING", (str,)) BINARY = _Type("BINARY", (bytes, bytearray, memoryview)) -NUMBER = _Type("NUMBER", (int, float)) +# `decimal.Decimal` is in here because PEP 249 puts every numeric +# column under NUMBER and a decimal is one. It is not in a set of its +# own: a program asking whether a column holds a number should get yes +# for a price, and the exact type is what the value already is. +NUMBER = _Type("NUMBER", (int, float, decimal.Decimal)) DATETIME = _Type("DATETIME", (datetime.date, datetime.time, datetime.datetime)) #: The values that identify a row, which in a graph are the ones that #: carry a table and an offset in it. diff --git a/python/zudb/types.py b/python/zudb/types.py index 347cab0..e69dbce 100644 --- a/python/zudb/types.py +++ b/python/zudb/types.py @@ -10,6 +10,7 @@ from __future__ import annotations import datetime +import decimal from typing import TypeAlias from ._zudb import Duration, Node, Path, Rel @@ -22,12 +23,15 @@ #: duration and hands one back, since a ``timedelta`` cannot hold every #: duration zu can. ``bytes`` and not ``bytearray``, because a parameter #: is read after the call that takes it returns and a mutable buffer is a -#: promise the caller can break. +#: promise the caller can break. A ``decimal.Decimal`` goes both ways +#: and is the one exact number here: a price read into a ``float`` would +#: not be the price, which is why the engine has a type for it at all. Value: TypeAlias = ( None | bool | int | float + | decimal.Decimal | str | bytes | datetime.date diff --git a/src/value.rs b/src/value.rs index 0331381..dd0856b 100644 --- a/src/value.rs +++ b/src/value.rs @@ -10,8 +10,9 @@ use std::collections::HashMap; use pyo3::prelude::*; +use pyo3::sync::PyOnceLock; use pyo3::types::{ - PyBool, PyBytes, PyDate, PyDateTime, PyDelta, PyDict, PyList, PyTime, PyTuple, PyTzInfo, + PyBool, PyBytes, PyDate, PyDateTime, PyDelta, PyDict, PyList, PyTime, PyTuple, PyType, PyTzInfo, }; use zu_common::temporal::{NANOS_PER_DAY, NANOS_PER_MINUTE, civil_from_days, days_from_civil}; use zu_common::{DurationKind, Temporal}; @@ -306,6 +307,26 @@ impl Duration { } } +/// `decimal.Decimal`, imported once and kept. +/// +/// The type object rather than the module, since both directions want +/// it: one to build a decimal and one to recognise a parameter that is +/// already one. `decimal` is in the standard library and importing it +/// costs a few hundred microseconds the first time, which is a price +/// worth paying once and not once a cell. +static DECIMAL: PyOnceLock> = PyOnceLock::new(); + +fn decimal_type(py: Python<'_>) -> PyResult<&Bound<'_, PyType>> { + DECIMAL + .get_or_try_init(py, || { + Ok(PyModule::import(py, "decimal")? + .getattr("Decimal")? + .downcast_into::()? + .unbind()) + }) + .map(|ty| ty.bind(py)) +} + /// One engine value as the Python object it is. pub fn to_py<'py>(py: Python<'py>, value: &Value, names: &Names) -> PyResult> { Ok(match value { @@ -321,6 +342,19 @@ pub fn to_py<'py>(py: Python<'py>, value: &Value, names: &Names) -> PyResult PyBytes::new(py, b).into_any(), + // `decimal.Decimal` and not `float`. The engine holds this + // exactly because a tenth is not a binary fraction, and handing + // it over as a float would lose both the value and the number + // of places on the last step of the journey. The standard + // library already has the type, so a notebook that reads a + // money column gets something it can add up without importing + // anything. + // + // Built from the text rather than from the digits and the + // scale, because `Decimal("1.20")` is the one constructor that + // is exact for both: it keeps two places where a float would + // keep neither, and the spelling is the one the engine prints. + Value::Decimal(d) => decimal_type(py)?.call1((d.to_string(),))?, Value::Node { table, offset } => Node { table: names.node(*table), offset: *offset, @@ -474,6 +508,44 @@ fn datetime_of<'py>( ) } +/// A `decimal.Decimal` as the engine's, exactly or not at all. +/// +/// Read through `format(d, "f")` rather than `str(d)`, because Python +/// prints some decimals with an exponent and `Decimal("1E+2")` is a +/// hundred at no places rather than a one at two of them. The `f` +/// format is always the digits written out, so the number of them after +/// the point is the scale and there is nothing left to interpret. +/// +/// Every refusal here is a value the engine has no decimal for, and +/// each says which: a NaN or an infinity is not an exact number at all, +/// thirty eight digits is the largest precision `DECIMAL(p, s)` takes +/// and the largest an i128 holds, and a scale past that is a number +/// whose point is further right than any column could declare. Failing +/// at the call is the point: a parameter that arrived as a float would +/// be a query comparing a price against something that is not it. +fn decimal_from_py(value: &Bound<'_, PyAny>) -> PyResult { + let plain: String = value.call_method1("__format__", ("f",))?.extract()?; + let scale = match plain.split_once('.') { + Some((_, fraction)) => fraction.len(), + None => 0, + }; + if scale > usize::from(zu_common::decimal::MAX_DIGITS) { + return Err(pyo3::exceptions::PyValueError::new_err(format!( + "the decimal {plain} has {scale} digits after the point, and a decimal here holds at \ + most {}", + zu_common::decimal::MAX_DIGITS + ))); + } + match zu_common::Decimal::parse(&plain, scale as u16) { + Some(d) => Ok(Value::Decimal(d)), + None => Err(pyo3::exceptions::PyValueError::new_err(format!( + "{plain} is not a decimal this engine holds: it takes an exact number of at most {} \ + digits, so a NaN, an infinity and anything wider are all outside it", + zu_common::decimal::MAX_DIGITS + ))), + } +} + /// An offset in minutes as a `datetime.timezone`. fn zone_of(py: Python<'_>, offset: i16) -> PyResult> { PyTzInfo::fixed_offset(py, PyDelta::new(py, 0, i32::from(offset) * 60, 0, true)?) @@ -528,6 +600,15 @@ fn nested(value: &Bound<'_, PyAny>, depth: usize) -> PyResult { if let Ok(b) = value.cast::() { return Ok(Value::Bytes(b.as_bytes().to_vec())); } + // Before the integer and the float arms, because a + // `decimal.Decimal` is neither and would go through `extract::` + // otherwise, which is the loss the caller picked the type to avoid. + // Read from `str(d)` for the reason it is built from a string: that + // is the spelling that carries both the digits and how many of them + // are after the point. + if value.is_instance(decimal_type(value.py())?.as_any())? { + return decimal_from_py(value); + } if let Ok(n) = value.extract::() { return Ok(Value::Int(n)); } diff --git a/tests/test_values.py b/tests/test_values.py index eecfbea..8963c55 100644 --- a/tests/test_values.py +++ b/tests/test_values.py @@ -3,6 +3,7 @@ from __future__ import annotations import datetime +import decimal import pytest import zudb @@ -105,3 +106,103 @@ def test_a_year_month_duration_has_no_timedelta() -> None: def test_a_duration_repr_names_the_count_it_carries() -> None: assert repr(zudb.Duration(months=3)) == "Duration(months=3)" assert repr(zudb.Duration(nanoseconds=3)) == "Duration(nanoseconds=3)" + + +def test_a_decimal_keeps_the_digits_it_was_written_with(empty: zudb.Connection) -> None: + """A tenth is not a binary fraction, so a price held as a float is + not the price and neither is the two places it printed at. The whole + reason the engine has the type is that both survive.""" + got = empty.execute("RETURN CAST('1.20' AS DECIMAL(5, 2)) AS v").fetchone()[0] + assert type(got) is decimal.Decimal + assert got == decimal.Decimal("1.20") + assert str(got) == "1.20" + assert got.as_tuple().exponent == -2 + + +@pytest.mark.parametrize( + "text", + ["0", "1.20", "-0.05", "1234", "-1234.5678", "0.005", "0.000"], +) +def test_a_decimal_reads_back_as_the_number_and_the_scale_it_was_cast_at( + empty: zudb.Connection, text: str +) -> None: + places = len(text.partition(".")[2]) + statement = f"RETURN CAST('{text}' AS DECIMAL(38, {places})) AS v" + got = empty.execute(statement).fetchone()[0] + assert got == decimal.Decimal(text) + assert str(got) == text + + +def test_a_decimal_is_not_the_float_that_looks_like_it(empty: zudb.Connection) -> None: + """0.1 as a float is a number slightly larger than a tenth, and this + is the case a client that reached for `float` would pass by getting + both of them wrong the same way.""" + got = empty.execute("RETURN CAST('0.1' AS DECIMAL(5, 1)) AS v").fetchone()[0] + assert got == decimal.Decimal("0.1") + assert got != decimal.Decimal(0.1) + assert float(got) == 0.1 + + +def test_a_decimal_wider_than_an_int64_arrives_whole(empty: zudb.Connection) -> None: + """Thirty eight digits is the largest precision DECIMAL(p, s) takes + and the largest the engine's carrier holds, so this is the widest + value that can come across.""" + digits = "12345678901234567890123456789012345678" + got = empty.execute(f"RETURN CAST('{digits}' AS DECIMAL(38, 0)) AS v").fetchone()[0] + assert got == decimal.Decimal(digits) + + +def test_a_decimal_goes_in_as_a_parameter_and_comes_back_the_same( + empty: zudb.Connection, +) -> None: + sent = decimal.Decimal("1.20") + got = empty.execute("RETURN $d AS v", {"d": sent}).fetchone()[0] + assert got == sent + assert str(got) == "1.20" + assert type(got) is decimal.Decimal + + +def test_a_decimal_parameter_is_not_read_as_a_float(empty: zudb.Connection) -> None: + """`decimal.Decimal` is neither an int nor a float, so a client that + fell through to `float` here would send a number that is not the one + the caller built, and the caller picked the type to avoid exactly + that.""" + got = empty.execute("RETURN $d AS v", {"d": decimal.Decimal("0.1")}).fetchone()[0] + assert type(got) is decimal.Decimal + assert got == decimal.Decimal("0.1") + + +def test_a_decimal_parameter_written_with_an_exponent_arrives_written_out( + empty: zudb.Connection, +) -> None: + """Python prints some decimals with an exponent and `Decimal("1E+2")` + is a hundred at no places rather than a one at two of them, so the + scale is taken off the digits written out rather than off the + spelling.""" + got = empty.execute("RETURN $d AS v", {"d": decimal.Decimal("1E+2")}).fetchone()[0] + assert got == decimal.Decimal(100) + assert str(got) == "100" + + +@pytest.mark.parametrize("text", ["NaN", "-NaN", "sNaN", "Infinity", "-Infinity"]) +def test_a_decimal_that_is_not_a_number_is_refused_at_the_call( + empty: zudb.Connection, text: str +) -> None: + """These are values `decimal.Decimal` holds and an exact number is + not, so there is nothing to send. Failing here is the point: a + parameter that arrived as something else would be a query answering + about a value nobody asked about.""" + with pytest.raises(ValueError, match="exact number"): + empty.execute("RETURN $d AS v", {"d": decimal.Decimal(text)}) + + +def test_a_decimal_with_more_places_than_the_engine_holds_says_so( + empty: zudb.Connection, +) -> None: + with pytest.raises(ValueError, match="after the point"): + empty.execute("RETURN $d AS v", {"d": decimal.Decimal("1E-100")}) + + +def test_a_decimal_wider_than_the_carrier_says_so(empty: zudb.Connection) -> None: + with pytest.raises(ValueError, match="at most 38"): + empty.execute("RETURN $d AS v", {"d": decimal.Decimal("1" * 40)}) From 48c7596ee54d739cd5c15d23a19f5b967e16fae9 Mon Sep 17 00:00:00 2001 From: Tam Nguyen Duc <1218621+tamnd@users.noreply.github.com> Date: Tue, 25 Aug 2026 13:41:41 +0700 Subject: [PATCH 2/5] Move the lock with the pin Three git dependencies point at the engine and the lock records the revision each of them resolved to, so a pin that moves without it is a build that fetches one commit and records another. --- Cargo.lock | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 79292f0..82c5c17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1735,7 +1735,7 @@ dependencies = [ [[package]] name = "zu" version = "0.0.1" -source = "git+https://github.com/tamnd/zu?rev=9dcb7b42b50f3a802cae62b18d9e99f30efefad1#9dcb7b42b50f3a802cae62b18d9e99f30efefad1" +source = "git+https://github.com/tamnd/zu?rev=cfdc70f291719309b96a8300dc8425154d0fd5d5#cfdc70f291719309b96a8300dc8425154d0fd5d5" dependencies = [ "zu-common", "zu-encoding", @@ -1751,7 +1751,7 @@ dependencies = [ [[package]] name = "zu-arrow" version = "0.0.1" -source = "git+https://github.com/tamnd/zu?rev=9dcb7b42b50f3a802cae62b18d9e99f30efefad1#9dcb7b42b50f3a802cae62b18d9e99f30efefad1" +source = "git+https://github.com/tamnd/zu?rev=cfdc70f291719309b96a8300dc8425154d0fd5d5#cfdc70f291719309b96a8300dc8425154d0fd5d5" dependencies = [ "arrow", "zu-common", @@ -1761,7 +1761,7 @@ dependencies = [ [[package]] name = "zu-common" version = "0.0.1" -source = "git+https://github.com/tamnd/zu?rev=9dcb7b42b50f3a802cae62b18d9e99f30efefad1#9dcb7b42b50f3a802cae62b18d9e99f30efefad1" +source = "git+https://github.com/tamnd/zu?rev=cfdc70f291719309b96a8300dc8425154d0fd5d5#cfdc70f291719309b96a8300dc8425154d0fd5d5" dependencies = [ "thiserror", ] @@ -1769,7 +1769,7 @@ dependencies = [ [[package]] name = "zu-encoding" version = "0.0.1" -source = "git+https://github.com/tamnd/zu?rev=9dcb7b42b50f3a802cae62b18d9e99f30efefad1#9dcb7b42b50f3a802cae62b18d9e99f30efefad1" +source = "git+https://github.com/tamnd/zu?rev=cfdc70f291719309b96a8300dc8425154d0fd5d5#cfdc70f291719309b96a8300dc8425154d0fd5d5" dependencies = [ "ruzstd", "zu-common", @@ -1778,7 +1778,7 @@ dependencies = [ [[package]] name = "zu-exec" version = "0.0.1" -source = "git+https://github.com/tamnd/zu?rev=9dcb7b42b50f3a802cae62b18d9e99f30efefad1#9dcb7b42b50f3a802cae62b18d9e99f30efefad1" +source = "git+https://github.com/tamnd/zu?rev=cfdc70f291719309b96a8300dc8425154d0fd5d5#cfdc70f291719309b96a8300dc8425154d0fd5d5" dependencies = [ "zu-common", "zu-query", @@ -1788,7 +1788,7 @@ dependencies = [ [[package]] name = "zu-query" version = "0.0.1" -source = "git+https://github.com/tamnd/zu?rev=9dcb7b42b50f3a802cae62b18d9e99f30efefad1#9dcb7b42b50f3a802cae62b18d9e99f30efefad1" +source = "git+https://github.com/tamnd/zu?rev=cfdc70f291719309b96a8300dc8425154d0fd5d5#cfdc70f291719309b96a8300dc8425154d0fd5d5" dependencies = [ "crossbeam-deque", "zu-common", @@ -1799,7 +1799,7 @@ dependencies = [ [[package]] name = "zu-s3" version = "0.0.1" -source = "git+https://github.com/tamnd/zu?rev=9dcb7b42b50f3a802cae62b18d9e99f30efefad1#9dcb7b42b50f3a802cae62b18d9e99f30efefad1" +source = "git+https://github.com/tamnd/zu?rev=cfdc70f291719309b96a8300dc8425154d0fd5d5#cfdc70f291719309b96a8300dc8425154d0fd5d5" dependencies = [ "crc32c", "object_store", @@ -1810,7 +1810,7 @@ dependencies = [ [[package]] name = "zu-sqlite" version = "0.0.1" -source = "git+https://github.com/tamnd/zu?rev=9dcb7b42b50f3a802cae62b18d9e99f30efefad1#9dcb7b42b50f3a802cae62b18d9e99f30efefad1" +source = "git+https://github.com/tamnd/zu?rev=cfdc70f291719309b96a8300dc8425154d0fd5d5#cfdc70f291719309b96a8300dc8425154d0fd5d5" dependencies = [ "rusqlite", "zu-common", @@ -1820,7 +1820,7 @@ dependencies = [ [[package]] name = "zu-storage" version = "0.0.1" -source = "git+https://github.com/tamnd/zu?rev=9dcb7b42b50f3a802cae62b18d9e99f30efefad1#9dcb7b42b50f3a802cae62b18d9e99f30efefad1" +source = "git+https://github.com/tamnd/zu?rev=cfdc70f291719309b96a8300dc8425154d0fd5d5#cfdc70f291719309b96a8300dc8425154d0fd5d5" dependencies = [ "zu-common", "zu-encoding", @@ -1829,7 +1829,7 @@ dependencies = [ [[package]] name = "zu-vector" version = "0.0.1" -source = "git+https://github.com/tamnd/zu?rev=9dcb7b42b50f3a802cae62b18d9e99f30efefad1#9dcb7b42b50f3a802cae62b18d9e99f30efefad1" +source = "git+https://github.com/tamnd/zu?rev=cfdc70f291719309b96a8300dc8425154d0fd5d5#cfdc70f291719309b96a8300dc8425154d0fd5d5" dependencies = [ "zu-common", ] @@ -1837,7 +1837,7 @@ dependencies = [ [[package]] name = "zu-zu1" version = "0.0.1" -source = "git+https://github.com/tamnd/zu?rev=9dcb7b42b50f3a802cae62b18d9e99f30efefad1#9dcb7b42b50f3a802cae62b18d9e99f30efefad1" +source = "git+https://github.com/tamnd/zu?rev=cfdc70f291719309b96a8300dc8425154d0fd5d5#cfdc70f291719309b96a8300dc8425154d0fd5d5" dependencies = [ "crc32c", "loom", From 5d97899569619be65951d33c130c86959bf0e336 Mon Sep 17 00:00:00 2001 From: Tam Nguyen Duc <1218621+tamnd@users.noreply.github.com> Date: Tue, 25 Aug 2026 14:05:05 +0700 Subject: [PATCH 3/5] Cast rather than downcast pyo3 0.29 renamed the downcast family to cast, which is what the rest of this crate already calls. The decimal type object was the one place still spelling it the old way, and it did not compile. --- src/value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/value.rs b/src/value.rs index dd0856b..5e7f585 100644 --- a/src/value.rs +++ b/src/value.rs @@ -321,7 +321,7 @@ fn decimal_type(py: Python<'_>) -> PyResult<&Bound<'_, PyType>> { .get_or_try_init(py, || { Ok(PyModule::import(py, "decimal")? .getattr("Decimal")? - .downcast_into::()? + .cast_into::()? .unbind()) }) .map(|ty| ty.bind(py)) From 099e5f9b9d3071a6a3b20901b1a1a7527ce5dcef Mon Sep 17 00:00:00 2001 From: Tam Nguyen Duc <1218621+tamnd@users.noreply.github.com> Date: Tue, 25 Aug 2026 14:11:10 +0700 Subject: [PATCH 4/5] Pay for the wider surface with a version The api gate compares the public surface against main and lets a change through once the version has moved, which is the same rule the engine gets from cargo semver-checks and the TypeScript client gets from its committed report. Two names moved here: Value now admits a decimal.Decimal and NUMBER now counts one as a number. Both are additions rather than removals, and both are still the surface changing, so the version moves with them. The wheel test that wanted two versions out of one build now wants 0.0.2 and 0.0.3, since 0.0.2 is no longer a version this project is not. --- Cargo.lock | 2 +- Cargo.toml | 2 +- pyproject.toml | 2 +- python/zudb/__init__.py | 2 +- tests/test_connection.py | 2 +- tests/test_wheels.py | 8 ++++---- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82c5c17..a4c1f8b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1847,7 +1847,7 @@ dependencies = [ [[package]] name = "zudb-python" -version = "0.0.1" +version = "0.0.2" dependencies = [ "arrow", "numpy", diff --git a/Cargo.toml b/Cargo.toml index 10dbe10..f08acdd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zudb-python" -version = "0.0.1" +version = "0.0.2" edition = "2024" rust-version = "1.98" license = "Apache-2.0" diff --git a/pyproject.toml b/pyproject.toml index f29dc2f..8c91935 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "zudb" -version = "0.0.1" +version = "0.0.2" description = "zu: an embedded property-graph database, in your process" readme = "README.md" license = "Apache-2.0" diff --git a/python/zudb/__init__.py b/python/zudb/__init__.py index da376ab..f87a8e0 100644 --- a/python/zudb/__init__.py +++ b/python/zudb/__init__.py @@ -55,7 +55,7 @@ ) from .types import Value -__version__ = "0.0.1" +__version__ = "0.0.2" __all__ = [ "connect", diff --git a/tests/test_connection.py b/tests/test_connection.py index 14d8dea..397590a 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -78,7 +78,7 @@ def test_repr_names_the_file_and_says_when_it_is_closed(tmp_path: Path) -> None: def test_the_engine_and_abi_versions_are_reported(empty: zudb.Connection) -> None: - assert zudb.__version__ == "0.0.1" + assert zudb.__version__ == "0.0.2" assert zudb.__abi_version__.count(".") == 1 diff --git a/tests/test_wheels.py b/tests/test_wheels.py index 5d2ec66..dced1b0 100644 --- a/tests/test_wheels.py +++ b/tests/test_wheels.py @@ -10,7 +10,7 @@ import wheel_tags -VERSION = "0.0.1" +VERSION = "0.0.2" def grid() -> list[str]: @@ -200,11 +200,11 @@ def test_a_build_that_produced_two_wheels_is_caught() -> None: # of them is the one that gets uploaded. built = [ f"zudb-{VERSION}-cp314-cp314t-manylinux_2_28_x86_64.whl", - "zudb-0.0.2-cp314-cp314t-manylinux_2_28_x86_64.whl", + "zudb-0.0.3-cp314-cp314t-manylinux_2_28_x86_64.whl", ] assert wheel_tags.check_one(built, "cp314-cp314t", "manylinux_2_28_x86_64") == [ - "2 wheels out of one build: zudb-0.0.1-cp314-cp314t-manylinux_2_28_x86_64.whl, " - "zudb-0.0.2-cp314-cp314t-manylinux_2_28_x86_64.whl" + "2 wheels out of one build: zudb-0.0.2-cp314-cp314t-manylinux_2_28_x86_64.whl, " + "zudb-0.0.3-cp314-cp314t-manylinux_2_28_x86_64.whl" ] From 9dbafa5cd3f5da0dadecbdba68480d3a4612d3f2 Mon Sep 17 00:00:00 2001 From: Tam Nguyen Duc <1218621+tamnd@users.noreply.github.com> Date: Tue, 25 Aug 2026 14:20:45 +0700 Subject: [PATCH 5/5] Make room in the import budget for decimal A Windows runner came in at 20.3 ms against a ceiling of 20, and the module that put it there is decimal, which costs about four milliseconds and is now imported at package scope because Value names decimal.Decimal. The alternative was to import it only for a type checker and leave the union as a string, which is cheaper and worse: Value stops being a real object, and every annotation that mentions it stops resolving under get_type_hints. The engine grew an exact decimal, so the package grew a module, and the ceiling says so. --- tests/test_import.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/test_import.py b/tests/test_import.py index d754668..5658fd9 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -27,13 +27,21 @@ #: Milliseconds for the Python around the extension, which is where #: growth would come from. The extension is the engine and is what it -#: is; the package is a dozen names, `datetime`, `typing`, and the union -#: that describes a value, and it costs about three milliseconds here, -#: most of it `typing`. A ceiling rather than a target: what it is meant -#: to catch is a module imported at package scope by somebody who did -#: not need it there, since each one of those costs milliseconds and -#: none of them costs enough to notice on its own. -OURS = 20.0 +#: is; the package is a dozen names, `datetime`, `decimal`, `typing`, +#: and the union that describes a value, and it costs about seven +#: milliseconds here, most of it `typing` and `decimal`. A ceiling +#: rather than a target: what it is meant to catch is a module imported +#: at package scope by somebody who did not need it there, since each +#: one of those costs milliseconds and none of them costs enough to +#: notice on its own. +#: +#: `decimal` is the one that was needed. An exact decimal is a value +#: this engine holds and hands back, so `Value` has to name the class, +#: and naming a class means importing the module it is in. It is the +#: most expensive import in the package, around four milliseconds, and +#: the ceiling moved by five when it arrived rather than the union +#: quietly becoming a string that no `get_type_hints` can resolve. +OURS = 25.0 #: Runs, because a machine that measures itself is a busy machine. The #: fastest says what the import costs and the middle one says the