Skip to content

Commit

Permalink
Use microseconds precision to work with macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi committed Jul 25, 2024
1 parent 1f787b0 commit bc10c3a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 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, nanoseconds
from pyarrow.includes.chrono cimport duration_cast, microseconds
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,7 +744,7 @@ cdef class FlightEndpoint(_Weakrefable):
self.endpoint.locations.push_back(c_location)

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

self.endpoint.app_metadata = tobytes(app_metadata)

Expand All @@ -763,10 +763,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_NANO, UTC)
shared_ptr[CTimestampType] time_type = make_shared[CTimestampType](TimeUnit.TimeUnit_MICRO, UTC)
shared_ptr[CTimestampScalar] shared
if self.endpoint.expiration_time.has_value():
time_since_epoch = duration_cast[nanoseconds](self.endpoint.expiration_time.value().time_since_epoch()).count()
time_since_epoch = duration_cast[microseconds](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)
return None
Expand Down
4 changes: 2 additions & 2 deletions python/pyarrow/includes/chrono.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ cdef extern from "<chrono>" namespace "std::chrono":
duration(int64_t count)
const int64_t count()

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

T duration_cast[T](duration d)

Expand Down
2 changes: 1 addition & 1 deletion python/pyarrow/tests/test_flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ def test_flight_get_info():
assert info.endpoints[0].app_metadata == b""
assert info.endpoints[0].locations[0] == flight.Location('grpc://test')
assert info.endpoints[1].expiration_time == \
pa.scalar("2023-04-05T12:34:56.789+00:00").cast(pa.timestamp("ns", "UTC"))
pa.scalar("2023-04-05T12:34:56.789+00:00").cast(pa.timestamp("us", "UTC"))
assert info.endpoints[1].app_metadata == b"endpoint app metadata"
assert info.endpoints[1].locations[0] == \
flight.Location.for_grpc_tcp('localhost', 5005)
Expand Down

0 comments on commit bc10c3a

Please sign in to comment.