Yes, it looks buggy to me, see
In [12]: arr = pa.array([-1, -2, -3], type='int32')
In [13]: arr.cast('uint8')
---------------------------------------------------------------------------
ArrowInvalid Traceback (most recent call last)
<ipython-input-13-114e7eb1dc7b> in <module>()
----> 1 arr.cast('uint8')
~/code/arrow/python/pyarrow/array.pxi in pyarrow.lib.Array.cast()
~/code/arrow/python/pyarrow/error.pxi in pyarrow.lib.check_status()
ArrowInvalid: ../src/arrow/compute/kernels/cast.cc:1196 code:
Cast(ctx, Datum(array.data()), out_type, options, &datum_out)
../src/arrow/compute/kernels/cast.cc:1186 code:
detail::InvokeUnaryArrayKernel(ctx, func.get(), value, &result)
../src/arrow/compute/kernels/util-internal.cc:40 code:
kernel->Call(ctx, value, &output)
Integer value out of bounds
In [14]: arr.cast('uint16')
---------------------------------------------------------------------------
ArrowInvalid Traceback (most recent call last)
<ipython-input-14-17fcf02f6c1c> in <module>()
----> 1 arr.cast('uint16')
~/code/arrow/python/pyarrow/array.pxi in pyarrow.lib.Array.cast()
~/code/arrow/python/pyarrow/error.pxi in pyarrow.lib.check_status()
ArrowInvalid: ../src/arrow/compute/kernels/cast.cc:1196 code:
Cast(ctx, Datum(array.data()), out_type, options, &datum_out)
../src/arrow/compute/kernels/cast.cc:1186 code:
detail::InvokeUnaryArrayKernel(ctx, func.get(), value, &result)
../src/arrow/compute/kernels/util-internal.cc:40 code:
kernel->Call(ctx, value, &output)
Integer value out of bounds
In [15]: arr.cast('uint32')
Out[15]:
<pyarrow.lib.UInt32Array object at 0x7fc61eca3778>
[
4294967295,
4294967294,
4294967293
]
On Wed, Nov 14, 2018 at 6:10 AM Romain Francois <[email protected]> wrote:
>
> I'm implementing Array$cast() in the R package, i.e.
> https://issues.apache.org/jira/browse/ARROW-3741?filter=12344983
>
> I'm seeing some weird results when casting from int32 to uint32 and uint64
> (I'm expecting errors here as it's supposed to be safe
>
> https://github.com/apache/arrow/pull/2959#issuecomment-438606974
>
> a <- array(-(1:3))
> a$cast(uint16())
> #> Error in Array__cast(self, target_type, options): Invalid: Integer value
> out of bounds
> a$cast(uint16())
> #> Error in Array__cast(self, target_type, options): Invalid: Integer value
> out of bounds
> a$cast(uint32())
> #> arrow::Array
> #> [
> #> 4294967295,
> #> 4294967294,
> #> 4294967293
> #> ]
> a$cast(uint32())$type()
> #> arrow::UInt32
> #> uint32
>
> a$cast(uint64())
> #> arrow::Array
> #> [
> #> -1,
> #> -2,
> #> -3
> #> ]
> a$cast(uint64())$type()
> #> arrow::UInt64
> #> uint64
>
> I don't think this is an R issue.
>
> Can someone using other front ends to the C++ library check if they get the
> same problem ?
>
>
>