66from __future__ import annotations
77
88import base64
9+ from typing import final
910
1011import pyarrow as pa
12+ from typing_extensions import override
1113
1214import vortex as vx
1315
1618_TIMESTAMP_US_METADATA = bytes ([1 , 0 , 0 ])
1719
1820
21+ @final
1922class VortexTimestampType (pa .ExtensionType ):
2023 """pyarrow `ExtensionType` matching Vortex's `vortex.timestamp`."""
2124
25+ _unit : str
26+
2227 def __init__ (self , unit : str = "us" ):
2328 # pyarrow calls `__arrow_ext_serialize__` from __init__, so `_unit` must be set first.
2429 self ._unit = unit
2530 pa .ExtensionType .__init__ (self , pa .int64 (), "vortex.timestamp" )
2631
32+ @override
2733 def __arrow_ext_serialize__ (self ) -> bytes :
2834 unit_tag = {"ns" : 0 , "us" : 1 , "ms" : 2 , "s" : 3 }[self ._unit ]
2935 return bytes ([unit_tag , 0 , 0 ])
3036
3137 @classmethod
32- def __arrow_ext_deserialize__ (cls , storage_type , serialized ): # noqa: ARG003
38+ @override
39+ def __arrow_ext_deserialize__ (
40+ cls ,
41+ storage_type : pa .DataType , # noqa: ARG003
42+ serialized : bytes ,
43+ ) -> VortexTimestampType :
3344 unit_tag = serialized [0 ]
3445 unit = {0 : "ns" , 1 : "us" , 2 : "ms" , 3 : "s" }[unit_tag ]
3546 return cls (unit )
@@ -38,7 +49,9 @@ def __arrow_ext_deserialize__(cls, storage_type, serialized): # noqa: ARG003
3849def test_chunked_extension_array_uses_session_for_leaf_extension_type ():
3950 ext_type = VortexTimestampType ()
4051 storage = pa .array ([1 , 2 , 3 ], type = pa .int64 ())
41- arrow = pa .chunked_array ([pa .ExtensionArray .from_storage (ext_type , storage )])
52+ arrow = pa .chunked_array (
53+ [pa .ExtensionArray .from_storage (ext_type , storage )] # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType]
54+ )
4255 array = vx .array (arrow )
4356 assert isinstance (array , vx .ChunkedArray )
4457 assert repr (array .dtype ) == repr (vx .timestamp ("us" ))
0 commit comments