jorisvandenbossche commented on a change in pull request #9560:
URL: https://github.com/apache/arrow/pull/9560#discussion_r582048115
##########
File path: python/pyarrow/types.pxi
##########
@@ -2386,25 +2426,102 @@ def struct(fields):
return pyarrow_wrap_data_type(struct_type)
-def union(children_fields, mode, type_codes=None):
+cdef _extract_union_params(child_fields, type_codes,
+ vector[shared_ptr[CField]]* c_fields,
+ vector[int8_t]* c_type_codes):
+ cdef:
+ Field child_field
+
+ for child_field in child_fields:
+ c_fields[0].push_back(child_field.sp_field)
+
+ if type_codes is not None:
+ if len(type_codes) != <Py_ssize_t>(c_fields.size()):
+ raise ValueError("type_codes should have the same length "
+ "as fields")
+ for code in type_codes:
+ c_type_codes[0].push_back(code)
+ else:
+ c_type_codes[0] = range(c_fields.size())
+
+
+def sparse_union(child_fields, type_codes=None):
"""
- Create UnionType from children fields.
+ Create SparseUnionType from child fields.
- A union is defined by an ordered sequence of types; each slot in the union
- can have a value chosen from these types.
+ A union is defined by an ordered sequence of child types; each slot in
+ the union can have a value chosen from these types.
Review comment:
Do we want to add the expanded explanation about sparse (or dense)
unions, that you added to the C++ code? (don't know to what extent we want to
duplicate this content, but right now the python docs don't have much
explanation about it)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]