@@ -263,7 +263,9 @@ def __str__(self) -> str:
263
263
return str (self ._inner )
264
264
265
265
def __repr__ (self ) -> str :
266
- return f"{ self .__class__ .__name__ } ({ self .raw ()!r} , { self .dtype !r} )"
266
+ return (
267
+ f"{ self .__class__ .__name__ } ({ self .raw ()!r} , { self .dtype .value !r} )"
268
+ )
267
269
268
270
@classmethod
269
271
def from_bytes (
@@ -627,6 +629,7 @@ class _InnerVector(_abc.ABC):
627
629
628
630
dtype : _t .ClassVar [VectorDType ]
629
631
size : _t .ClassVar [int ]
632
+ cypher_inner_type_repr : _t .ClassVar [str ]
630
633
_data : bytes
631
634
_data_le : bytes | None
632
635
@@ -676,6 +679,8 @@ def data_le(self, data: bytes, /) -> None:
676
679
677
680
def __init_subclass__ (cls ) -> None :
678
681
super ().__init_subclass__ ()
682
+ if _abc .ABC in cls .__bases__ :
683
+ return
679
684
dtype = getattr (cls , "dtype" , None )
680
685
if not isinstance (dtype , VectorDType ):
681
686
raise TypeError (
@@ -703,7 +708,12 @@ def __len__(self) -> int:
703
708
704
709
def __str__ (self ) -> str :
705
710
size = len (self )
706
- return f"Vec[{ self .dtype } ; { size } ]"
711
+ type_repr = self .cypher_inner_type_repr
712
+ values_repr = self ._cypher_values_repr ()
713
+ return f"vector({ values_repr } , { size } , { type_repr } )"
714
+
715
+ @_abc .abstractmethod
716
+ def _cypher_values_repr (self ) -> str : ...
707
717
708
718
def __repr__ (self ) -> str :
709
719
cls_name = self .__class__ .__name__
@@ -743,11 +753,20 @@ def from_pyarrow(cls, data: pyarrow.Array, /) -> _t.Self:
743
753
def to_pyarrow (self ) -> pyarrow .Array : ...
744
754
745
755
746
- class _VecF64 (_InnerVector ):
756
+ class _InnerVectorFloat (_InnerVector , _abc .ABC ):
757
+ __slots__ = ()
758
+
759
+ def _cypher_values_repr (self ) -> str :
760
+ res = str (self .to_native ())
761
+ return res .replace ("nan" , "NaN" ).replace ("inf" , "Infinity" )
762
+
763
+
764
+ class _VecF64 (_InnerVectorFloat ):
747
765
__slots__ = ()
748
766
749
767
dtype = VectorDType .F64
750
768
size = 8
769
+ cypher_inner_type_repr = "FLOAT NOT NULL"
751
770
752
771
@classmethod
753
772
def _from_native_rust (cls , data : _t .Iterable [object ], / ) -> _t .Self :
@@ -817,11 +836,12 @@ def to_pyarrow(self) -> pyarrow.Array:
817
836
)
818
837
819
838
820
- class _VecF32 (_InnerVector ):
839
+ class _VecF32 (_InnerVectorFloat ):
821
840
__slots__ = ()
822
841
823
842
dtype = VectorDType .F32
824
843
size = 4
844
+ cypher_inner_type_repr = "FLOAT32 NOT NULL"
825
845
826
846
@classmethod
827
847
def _from_native_rust (cls , data : _t .Iterable [object ], / ) -> _t .Self :
@@ -891,15 +911,23 @@ def to_pyarrow(self) -> pyarrow.Array:
891
911
)
892
912
893
913
914
+ class _InnerVectorInt (_InnerVector , _abc .ABC ):
915
+ __slots__ = ()
916
+
917
+ def _cypher_values_repr (self ) -> str :
918
+ return str (self .to_native ())
919
+
920
+
894
921
_I64_MIN = - 9_223_372_036_854_775_808
895
922
_I64_MAX = 9_223_372_036_854_775_807
896
923
897
924
898
- class _VecI64 (_InnerVector ):
925
+ class _VecI64 (_InnerVectorInt ):
899
926
__slots__ = ()
900
927
901
928
dtype = VectorDType .I64
902
929
size = 8
930
+ cypher_inner_type_repr = "INTEGER NOT NULL"
903
931
904
932
@classmethod
905
933
def _from_native_rust (cls , data : _t .Iterable [object ], / ) -> _t .Self :
@@ -987,11 +1015,12 @@ def to_pyarrow(self) -> pyarrow.Array:
987
1015
_I32_MAX = 2_147_483_647
988
1016
989
1017
990
- class _VecI32 (_InnerVector ):
1018
+ class _VecI32 (_InnerVectorInt ):
991
1019
__slots__ = ()
992
1020
993
1021
dtype = VectorDType .I32
994
1022
size = 4
1023
+ cypher_inner_type_repr = "INTEGER32 NOT NULL"
995
1024
996
1025
@classmethod
997
1026
def _from_native_rust (cls , data : _t .Iterable [object ], / ) -> _t .Self :
@@ -1079,11 +1108,12 @@ def to_pyarrow(self) -> pyarrow.Array:
1079
1108
_I16_MAX = 32_767
1080
1109
1081
1110
1082
- class _VecI16 (_InnerVector ):
1111
+ class _VecI16 (_InnerVectorInt ):
1083
1112
__slots__ = ()
1084
1113
1085
1114
dtype = VectorDType .I16
1086
1115
size = 2
1116
+ cypher_inner_type_repr = "INTEGER16 NOT NULL"
1087
1117
1088
1118
@classmethod
1089
1119
def _from_native_rust (cls , data : _t .Iterable [object ], / ) -> _t .Self :
@@ -1171,11 +1201,12 @@ def to_pyarrow(self) -> pyarrow.Array:
1171
1201
_I8_MAX = 127
1172
1202
1173
1203
1174
- class _VecI8 (_InnerVector ):
1204
+ class _VecI8 (_InnerVectorInt ):
1175
1205
__slots__ = ()
1176
1206
1177
1207
dtype = VectorDType .I8
1178
1208
size = 1
1209
+ cypher_inner_type_repr = "INTEGER8 NOT NULL"
1179
1210
1180
1211
@classmethod
1181
1212
def _from_native_rust (cls , data : _t .Iterable [object ], / ) -> _t .Self :
0 commit comments