Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions python/pyarrow/array.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ cdef set PRIMITIVE_TYPES = set([
_Type_UINT32, _Type_INT32,
_Type_UINT64, _Type_INT64,
_Type_TIMESTAMP, _Type_DATE32,
_Type_TIME32, _Type_TIME64,
_Type_DATE64,
_Type_HALF_FLOAT,
_Type_FLOAT,
Expand Down Expand Up @@ -816,6 +817,32 @@ cdef class Date64Value(ArrayValue):
ap.Value(self.index) / 1000).date()


cdef class Time32Value(ArrayValue):

def as_py(self):
cdef:
CTime32Array* ap = <CTime32Array*> self.sp_array.get()
CTime32Type* dtype = <CTime32Type*> ap.type().get()

if dtype.unit() == TimeUnit_SECOND:
return (datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=ap.Value(self.index))).time()
else:
return (datetime.datetime(1970, 1, 1) + datetime.timedelta(milliseconds=ap.Value(self.index))).time()


cdef class Time64Value(ArrayValue):

def as_py(self):
cdef:
CTime64Array* ap = <CTime64Array*> self.sp_array.get()
CTime64Type* dtype = <CTime64Type*> ap.type().get()

if dtype.unit() == TimeUnit_MICRO:
return (datetime.datetime(1970, 1, 1) + datetime.timedelta(microseconds=ap.Value(self.index))).time()
else:
return (datetime.datetime(1970, 1, 1) + datetime.timedelta(microseconds=ap.Value(self.index) / 1000)).time()


cdef dict DATETIME_CONVERSION_FUNCTIONS

try:
Expand Down Expand Up @@ -975,6 +1002,8 @@ cdef dict _scalar_classes = {
_Type_INT64: Int64Value,
_Type_DATE32: Date32Value,
_Type_DATE64: Date64Value,
_Type_TIME32: Time32Value,
_Type_TIME64: Time64Value,
_Type_TIMESTAMP: TimestampValue,
_Type_FLOAT: FloatValue,
_Type_DOUBLE: DoubleValue,
Expand Down
6 changes: 6 additions & 0 deletions python/pyarrow/includes/libarrow.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
cdef cppclass CDate64Array" arrow::Date64Array"(CArray):
int64_t Value(int i)

cdef cppclass CTime32Array" arrow::Time32Array"(CArray):
int32_t Value(int i)

cdef cppclass CTime64Array" arrow::Time64Array"(CArray):
int64_t Value(int i)

cdef cppclass CTimestampArray" arrow::TimestampArray"(CArray):
int64_t Value(int i)

Expand Down
4 changes: 2 additions & 2 deletions python/pyarrow/tests/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,13 +449,13 @@ def test_date_time_types():

table = pa.Table.from_arrays([a1, a2, a3, a4, a5, a6],
['date32', 'date64', 'timestamp[us]',
'time32[s]', 'time64[us]', 'time32[s]'])
'time32[s]', 'time64[us]', 'time32_from64[s]'])

# date64 as date32
# time32[s] to time32[ms]
expected = pa.Table.from_arrays([a1, a1, a3, a4, a5, ex_a6],
['date32', 'date64', 'timestamp[us]',
'time32[s]', 'time64[us]', 'time32[s]'])
'time32[s]', 'time64[us]', 'time32_from64[s]'])

_check_roundtrip(table, expected=expected, version='2.0')

Expand Down