AlenkaF commented on code in PR #44434: URL: https://github.com/apache/arrow/pull/44434#discussion_r1979184881
########## python/scripts/test_scalar.py: ########## @@ -0,0 +1,28 @@ +import pyarrow as pa Review Comment: The test should be in https://github.com/apache/arrow/blob/main/python/pyarrow/tests/test_scalars.py. Can you also check the existing tests for array constructors and do similar? https://github.com/apache/arrow/blob/6d75b0e6e1b049089fb11955103a44bbc495bd92/python/pyarrow/tests/test_array.py#L3611-L3616 https://github.com/apache/arrow/blob/6d75b0e6e1b049089fb11955103a44bbc495bd92/python/pyarrow/tests/test_array.py#L3628-L3637 ########## python/pyarrow/scalar.pxi: ########## @@ -1235,6 +1235,13 @@ def scalar(value, type=None, *, from_pandas=None, MemoryPool memory_pool=None): ty = ensure_type(type) options.type = ty.sp_type + cdef shared_ptr[CArray] c_array + + if hasattr(value, "__arrow_c_array__"): + c_array = pyarrow_unwrap_array(value.__arrow_c_array__()) + if c_array.get().length() != 1: + raise ValueError("Expected a length-1 array for scalar construction") + Review Comment: Can you look at how the array constructor handles arrays that implement the Arrow PyCapsule Protocol and try to do similar? https://github.com/apache/arrow/blob/6d75b0e6e1b049089fb11955103a44bbc495bd92/python/pyarrow/array.pxi#L268-L279 Note that you have to return an object which should be a Scalar. To retrieve the scalar from pyarrow array of length 1 see the code bellow, at the end of this method. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
