Skip to content

Commit fdd559a

Browse files
committed
Simplified code [skip ci]
1 parent 0b4a61c commit fdd559a

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

pgvector/django/halfvec.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ def from_db_value(self, value: Any, expression: Any, connection: Any) -> list[fl
2828
return HalfVector._from_db(value)
2929

3030
def to_python(self, value: Any) -> list[float] | None:
31-
if value is None or isinstance(value, list):
31+
if isinstance(value, list):
3232
return value
33-
if isinstance(value, str):
34-
value = HalfVector.from_text(value)
35-
elif not isinstance(value, HalfVector):
36-
value = HalfVector(value)
37-
return value.to_list() # type: ignore
33+
return HalfVector._from_db(value)
3834

3935
def get_prep_value(self, value: Any) -> str | None:
4036
return HalfVector._to_db(value)

pgvector/django/vector.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ def from_db_value(self, value: Any, expression: Any, connection: Any) -> list[fl
2828
return Vector._from_db(value)
2929

3030
def to_python(self, value: Any) -> list[float] | None:
31-
if value is None or isinstance(value, list):
31+
if isinstance(value, list):
3232
return value
33-
if isinstance(value, str):
34-
value = Vector.from_text(value)
35-
elif not isinstance(value, Vector):
36-
value = Vector(value)
37-
return value.to_list() # type: ignore
33+
return Vector._from_db(value)
3834

3935
def get_prep_value(self, value: Any) -> str | None:
4036
return Vector._to_db(value)

0 commit comments

Comments
 (0)