This is an automated email from the ASF dual-hosted git repository.
jorisvandenbossche pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 84101a55fc ARROW-18264: [Python] Add missing value accessor to
temporal types (#14746)
84101a55fc is described below
commit 84101a55fcfc9aa7f80518722f8c56c2d033864f
Author: 0x26res <[email protected]>
AuthorDate: Tue Dec 13 13:48:55 2022 +0000
ARROW-18264: [Python] Add missing value accessor to temporal types (#14746)
Authored-by: aandres <[email protected]>
Signed-off-by: Joris Van den Bossche <[email protected]>
---
python/pyarrow/scalar.pxi | 10 ++++++++++
python/pyarrow/tests/test_scalars.py | 20 +++++++++++++++++++-
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/python/pyarrow/scalar.pxi b/python/pyarrow/scalar.pxi
index 0693f04fb7..73964d243a 100644
--- a/python/pyarrow/scalar.pxi
+++ b/python/pyarrow/scalar.pxi
@@ -345,6 +345,11 @@ cdef class Date32Scalar(Scalar):
Concrete class for date32 scalars.
"""
+ @property
+ def value(self):
+ cdef CDate32Scalar* sp = <CDate32Scalar*> self.wrapped.get()
+ return sp.value if sp.is_valid else None
+
def as_py(self):
"""
Return this value as a Python datetime.datetime instance.
@@ -365,6 +370,11 @@ cdef class Date64Scalar(Scalar):
Concrete class for date64 scalars.
"""
+ @property
+ def value(self):
+ cdef CDate64Scalar* sp = <CDate64Scalar*> self.wrapped.get()
+ return sp.value if sp.is_valid else None
+
def as_py(self):
"""
Return this value as a Python datetime.datetime instance.
diff --git a/python/pyarrow/tests/test_scalars.py
b/python/pyarrow/tests/test_scalars.py
index 9fa9d008a7..f417d58c8c 100644
--- a/python/pyarrow/tests/test_scalars.py
+++ b/python/pyarrow/tests/test_scalars.py
@@ -244,14 +244,32 @@ def test_time_from_datetime_time():
@pytest.mark.parametrize(['value', 'time_type'], [
(1, pa.time32("s")),
(2**30, pa.time32("s")),
+ (None, pa.time32("s")),
(1, pa.time32("ms")),
(2**30, pa.time32("ms")),
+ (None, pa.time32("ms")),
(1, pa.time64("us")),
(2**62, pa.time64("us")),
+ (None, pa.time64("us")),
(1, pa.time64("ns")),
(2**62, pa.time64("ns")),
+ (None, pa.time64("ns")),
+ (1, pa.date32()),
+ (2**30, pa.date32()),
+ (None, pa.date32()),
+ (1, pa.date64()),
+ (2**62, pa.date64()),
+ (None, pa.date64()),
+ (1, pa.timestamp("ns")),
+ (2**62, pa.timestamp("ns")),
+ (None, pa.timestamp("ns")),
+ (1, pa.duration("ns")),
+ (2**62, pa.duration("ns")),
+ (None, pa.duration("ns")),
+ ((1, 2, -3), pa.month_day_nano_interval()),
+ (None, pa.month_day_nano_interval()),
])
-def test_time_values(value, time_type):
+def test_temporal_values(value, time_type: pa.DataType):
time_scalar = pa.scalar(value, type=time_type)
assert time_scalar.value == value