Skip to content

Commit

Permalink
apacheGH-38010: [Python] Construct pyarrow.Field from Arrow-compatibl…
Browse files Browse the repository at this point in the history
…e schema object (PyCapsule protocol)
  • Loading branch information
jorisvandenbossche committed Mar 27, 2024
1 parent 24feab0 commit 6cf35cb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion python/pyarrow/types.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -3462,7 +3462,7 @@ cdef DataType primitive_type(Type type):
# Type factory functions


def field(name, type, bint nullable=True, metadata=None):
def field(name, type=None, bint nullable=True, metadata=None):
"""
Create a pyarrow.Field instance.
Expand Down Expand Up @@ -3504,6 +3504,14 @@ def field(name, type, bint nullable=True, metadata=None):
>>> pa.struct([field])
StructType(struct<key: int32>)
"""
if hasattr(name, "__arrow_c_schema__"):
if not (type is None and metadata is None):
raise ValueError(
"cannot specify 'type' or 'metadata' when creating a Field "
"from an ArrowSchema"
)
return Field._import_from_c_capsule(name.__arrow_c_schema__())

cdef:
Field result = Field.__new__(Field)
DataType _type = ensure_type(type, allow_none=False)
Expand Down

0 comments on commit 6cf35cb

Please sign in to comment.