milesgranger commented on code in PR #14106:
URL: https://github.com/apache/arrow/pull/14106#discussion_r972915628
##########
cpp/src/arrow/compute/kernels/scalar_cast_numeric.cc:
##########
@@ -769,6 +770,36 @@ std::vector<std::shared_ptr<CastFunction>>
GetNumericCasts() {
return functions;
}
+
+Status CastToExtension(KernelContext* ctx, const ExecSpan& batch, ExecResult*
out) {
+ const CastOptions& options = checked_cast<const
CastState*>(ctx->state())->options;
+ DCHECK(batch[0].is_array());
+ std::shared_ptr<Array> array = batch[0].array.ToArray();
+ std::shared_ptr<Array> result;
+
+ auto out_ty = GetExtensionType("arrow.py_integer_type")->storage_type();
+ RETURN_NOT_OK(Cast(*array, out_ty, options,
+ ctx->exec_context())
+ .Value(&result));
+
+ ExtensionArray extension(options.to_type.GetSharedPtr(), result);
+ out->value = std::move(extension.data());
+ return Status::OK();
+}
Review Comment:
@pitrou @rok This 'works', but need to hard-code the extension type name
here. I think if I can convert the
`options.to_type.GetSharedPtr()->storage_id()` into a `TypeHolder/DataType`
then I may be in the clear. Would either of you be able to help pointer me to
the correct approach? 🙏
```python
In [2]: from pyarrow.tests.test_extension_type import UuidType, IntegerType
In [3]: import pyarrow as pa
In [4]: pa.register_extension_type(IntegerType())
In [5]: a = pa.array([1, 2, 3], pa.int64())
In [6]: a.cast(IntegerType()).type
Out[6]: IntegerType(DataType(int64))
In [7]: a.cast(IntegerType())
Out[7]:
<pyarrow.lib.ExtensionArray object at 0x7f1167289520>
[
1,
2,
3
]
```
--
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]