Skip to content

Commit

Permalink
Cast expiration_time given to FlightEndpoint() to time_point::duration
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi committed Aug 5, 2024
1 parent d7e3df5 commit a53d4c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions python/pyarrow/_flight.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ from pyarrow.lib cimport *
from pyarrow.lib import (ArrowCancelled, ArrowException, ArrowInvalid,
SignalStopHandler)
from pyarrow.lib import as_buffer, frombytes, timestamp, tobytes
from pyarrow.includes.chrono cimport duration_cast, microseconds
from pyarrow.includes.chrono cimport duration_cast, nanoseconds
from pyarrow.includes.libarrow_flight cimport *
from pyarrow.ipc import _get_legacy_format_default, _ReadPandasMixin
import pyarrow.lib as lib
Expand Down Expand Up @@ -744,8 +744,8 @@ cdef class FlightEndpoint(_Weakrefable):
self.endpoint.locations.push_back(c_location)

if expiration_time is not None:
self.endpoint.expiration_time = time_point(
microseconds(expiration_time.cast(timestamp("us")).value))
self.endpoint.expiration_time = time_point(duration_cast[time_point.duration](
nanoseconds(expiration_time.cast(timestamp("ns")).value)))

self.endpoint.app_metadata = tobytes(app_metadata)

Expand All @@ -764,10 +764,10 @@ cdef class FlightEndpoint(_Weakrefable):
cdef:
int64_t time_since_epoch
const char* UTC = "UTC"
shared_ptr[CTimestampType] time_type = make_shared[CTimestampType](TimeUnit.TimeUnit_MICRO, UTC)
shared_ptr[CTimestampType] time_type = make_shared[CTimestampType](TimeUnit.TimeUnit_NANO, UTC)
shared_ptr[CTimestampScalar] shared
if self.endpoint.expiration_time.has_value():
time_since_epoch = duration_cast[microseconds](
time_since_epoch = duration_cast[nanoseconds](
self.endpoint.expiration_time.value().time_since_epoch()).count()
shared = make_shared[CTimestampScalar](time_since_epoch, time_type)
return Scalar.wrap(<shared_ptr[CScalar]> shared)
Expand Down
5 changes: 3 additions & 2 deletions python/pyarrow/includes/chrono.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ cdef extern from "<chrono>" namespace "std::chrono":
duration(int64_t count)
const int64_t count()

cdef cppclass microseconds(duration):
microseconds(int64_t count)
cdef cppclass nanoseconds(duration):
nanoseconds(int64_t count)

T duration_cast[T](duration d)

Expand All @@ -35,3 +35,4 @@ cdef extern from "<chrono>" namespace "std::chrono::system_clock":
cdef cppclass time_point:
time_point(const duration& d)
const duration time_since_epoch()
ctypedef duration duration

0 comments on commit a53d4c2

Please sign in to comment.