8000 Migrated custom UUID conversion logic to pyo3.uuid package by SaiSakthidar · Pull Request #663 · cocoindex-io/cocoindex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Migrated custom UUID conversion logic to pyo3.uuid package #663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ name = "cocoindex_engine"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.25.0", features = ["chrono", "auto-initialize"] }
pyo3 = { version = "0.25.0", features = ["chrono", "auto-initialize", "uuid"] }
pythonize = "0.25.0"
pyo3-async-runtimes = { version = "0.25.0", features = ["tokio-runtime"] }

Expand Down
5 changes: 0 additions & 5 deletions python/cocoindex/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ def encode_engine_value(value: Any) -> Any:
return [
[encode_engine_value(k)] + encode_engine_value(v) for k, v in value.items()
]
if isinstance(value, uuid.UUID):
return value.bytes
return value


Expand Down Expand Up @@ -92,9 +90,6 @@ def make_engine_value_decoder(
f"passed in {src_type_kind}, declared {dst_annotation} ({dst_type_info.kind})"
)

if src_type_kind == "Uuid":
return lambda value: uuid.UUID(bytes=value)

if dst_type_info is None:
if src_type_kind == "Struct" or src_type_kind in TABLE_TYPES:
raise ValueError(
Expand Down
8 changes: 4 additions & 4 deletions python/cocoindex/tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_encode_engine_value_basic_types() -> None:

def test_encode_engine_value_uuid() -> None:
u = uuid.uuid4()
assert encode_engine_value(u) == u.bytes
assert encode_engine_value(u) == u


def test_encode_engine_value_date_time_types() -> None:
Expand Down Expand Up @@ -285,8 +285,8 @@ def test_non_ndarray_vector_decoding() -> None:
decoder = make_engine_value_decoder(["field"], src_type, dst_type_uuid)
uuid1 = uuid.uuid4()
uuid2 = uuid.uuid4()
input_bytes = [uuid1.bytes, uuid2.bytes]
result = decoder(input_bytes)
input_uuids = [uuid1, uuid2]
result = decoder(input_uuids)
assert isinstance(result, list)
assert all(isinstance(x, uuid.UUID) for x in result)
assert result == [uuid1, uuid2]
Expand Down Expand Up @@ -579,7 +579,7 @@ def test_roundtrip_union_simple() -> None:

def test_roundtrip_union_with_active_uuid() -> None:
t = str | uuid.UUID | int
value = uuid.uuid4().bytes
value = uuid.uuid4()
validate_full_roundtrip(value, t)


Expand Down
4 changes: 2 additions & 2 deletions src/py/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn basic_value_to_py_object<'py>(
value::BasicValue::Float32(v) => v.into_bound_py_any(py)?,
value::BasicValue::Float64(v) => v.into_bound_py_any(py)?,
value::BasicValue::Range(v) => pythonize(py, v).into_py_result()?,
value::BasicValue::Uuid(v) => v.as_bytes().into_bound_py_any(py)?,
value::BasicValue::Uuid(uuid_val) => uuid_val.into_bound_py_any(py)?,
value::BasicValue::Date(v) => v.into_bound_py_any(py)?,
value::BasicValue::Time(v) => v.into_bound_py_any(py)?,
value::BasicValue::LocalDateTime(v) => v.into_bound_py_any(py)?,
Expand Down Expand Up @@ -137,7 +137,7 @@ fn basic_value_from_py_object<'py>(
schema::BasicValueType::Float64 => value::BasicValue::Float64(v.extract::<f64>()?),
schema::BasicValueType::Range => value::BasicValue::Range(depythonize(v)?),
schema::BasicValueType::Uuid => {
value::BasicValue::Uuid(uuid::Uuid::from_bytes(v.extract::<uuid::Bytes>()?))
value::BasicValue::Uuid(v.extract::<uuid::Uuid>()?)
}
schema::BasicValueType::Date => value::BasicValue::Date(v.extract::<chrono::NaiveDate>()?),
schema::BasicValueType::Time => value::BasicValue::Time(v.extract::<chrono::NaiveTime>()?),
Expand Down
Loading
0