Skip to content

Commit 9568f6d

Browse files
SaiSakthidarSK-47
andauthored
Migrated custom UUID conversion logic to pyo3.uuid package (#663)
* migrated custom UUID conversion logic to pyo3.uuid package * refractor: removed redundant logic --------- Co-authored-by: SKsai <[email protected]>
1 parent 9c590be commit 9568f6d

File tree

5 files changed

+8
-12
lines changed

5 files changed

+8
-12
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ name = "cocoindex_engine"
1515
crate-type = ["cdylib"]
1616

1717
[dependencies]
18-
pyo3 = { version = "0.25.0", features = ["chrono", "auto-initialize"] }
18+
pyo3 = { version = "0.25.0", features = ["chrono", "auto-initialize", "uuid"] }
1919
pythonize = "0.25.0"
2020
pyo3-async-runtimes = { version = "0.25.0", features = ["tokio-runtime"] }
2121

python/cocoindex/convert.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ def encode_engine_value(value: Any) -> Any:
4242
return [
4343
[encode_engine_value(k)] + encode_engine_value(v) for k, v in value.items()
4444
]
45-
if isinstance(value, uuid.UUID):
46-
return value.bytes
4745
return value
4846

4947

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

95-
if src_type_kind == "Uuid":
96-
return lambda value: uuid.UUID(bytes=value)
97-
9893
if dst_type_info is None:
9994
if src_type_kind == "Struct" or src_type_kind in TABLE_TYPES:
10095
raise ValueError(

python/cocoindex/tests/test_convert.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_encode_engine_value_basic_types() -> None:
122122

123123
def test_encode_engine_value_uuid() -> None:
124124
u = uuid.uuid4()
125-
assert encode_engine_value(u) == u.bytes
125+
assert encode_engine_value(u) == u
126126

127127

128128
def test_encode_engine_value_date_time_types() -> None:
@@ -285,8 +285,8 @@ def test_non_ndarray_vector_decoding() -> None:
285285
decoder = make_engine_value_decoder(["field"], src_type, dst_type_uuid)
286286
uuid1 = uuid.uuid4()
287287
uuid2 = uuid.uuid4()
288-
input_bytes = [uuid1.bytes, uuid2.bytes]
289-
result = decoder(input_bytes)
288+
input_uuids = [uuid1, uuid2]
289+
result = decoder(input_uuids)
290290
assert isinstance(result, list)
291291
assert all(isinstance(x, uuid.UUID) for x in result)
292292
assert result == [uuid1, uuid2]
@@ -579,7 +579,7 @@ def test_roundtrip_union_simple() -> None:
579579

580580
def test_roundtrip_union_with_active_uuid() -> None:
581581
t = str | uuid.UUID | int
582-
value = uuid.uuid4().bytes
582+
value = uuid.uuid4()
583583
validate_full_roundtrip(value, t)
584584

585585

src/py/convert.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn basic_value_to_py_object<'py>(
6969
value::BasicValue::Float32(v) => v.into_bound_py_any(py)?,
7070
value::BasicValue::Float64(v) => v.into_bound_py_any(py)?,
7171
value::BasicValue::Range(v) => pythonize(py, v).into_py_result()?,
72-
value::BasicValue::Uuid(v) => v.as_bytes().into_bound_py_any(py)?,
72+
value::BasicValue::Uuid(uuid_val) => uuid_val.into_bound_py_any(py)?,
7373
value::BasicValue::Date(v) => v.into_bound_py_any(py)?,
7474
value::BasicValue::Time(v) => v.into_bound_py_any(py)?,
7575
value::BasicValue::LocalDateTime(v) => v.into_bound_py_any(py)?,
@@ -137,7 +137,7 @@ fn basic_value_from_py_object<'py>(
137137
schema::BasicValueType::Float64 => value::BasicValue::Float64(v.extract::<f64>()?),
138138
schema::BasicValueType::Range => value::BasicValue::Range(depythonize(v)?),
139139
schema::BasicValueType::Uuid => {
140-
value::BasicValue::Uuid(uuid::Uuid::from_bytes(v.extract::<uuid::Bytes>()?))
140+
value::BasicValue::Uuid(v.extract::<uuid::Uuid>()?)
141141
}
142142
schema::BasicValueType::Date => value::BasicValue::Date(v.extract::<chrono::NaiveDate>()?),
143143
schema::BasicValueType::Time => value::BasicValue::Time(v.extract::<chrono::NaiveTime>()?),

0 commit comments

Comments
 (0)