Skip to content

Commit

Permalink
Document pa.field(str, str)
Browse files Browse the repository at this point in the history
  • Loading branch information
amoeba committed Oct 23, 2024
1 parent fc96747 commit e05e527
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions python/pyarrow/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,13 @@ def test_field_basic():
pa.field('foo', None)


def test_field_datatype_alias():
f = pa.field('foo', 'string')

assert f.name == 'foo'
assert f.type is pa.string()


def test_field_equals():
meta1 = {b'foo': b'bar'}
meta2 = {b'bizz': b'bazz'}
Expand Down
9 changes: 7 additions & 2 deletions python/pyarrow/types.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -3713,8 +3713,8 @@ def field(name, type=None, nullable=None, metadata=None):
Name of the field.
Alternatively, you can also pass an object that implements the Arrow
PyCapsule Protocol for schemas (has an ``__arrow_c_schema__`` method).
type : pyarrow.DataType
Arrow datatype of the field.
type : pyarrow.DataType or str
Arrow datatype of the field or a string matching one.
nullable : bool, default True
Whether the field's values are nullable.
metadata : dict, default None
Expand Down Expand Up @@ -3746,6 +3746,11 @@ def field(name, type=None, nullable=None, metadata=None):
>>> pa.struct([field])
StructType(struct<key: int32>)
A str can also be passed for the type parameter:
>>> pa.field('key', 'int32')
pyarrow.Field<key: int32>
"""
if hasattr(name, "__arrow_c_schema__"):
if type is not None:
Expand Down

0 comments on commit e05e527

Please sign in to comment.