From e05e5274579442f6f0ebe156085f010bdfb99096 Mon Sep 17 00:00:00 2001 From: Bryce Mecum Date: Wed, 23 Oct 2024 08:42:19 -0700 Subject: [PATCH] Document pa.field(str, str) --- python/pyarrow/tests/test_types.py | 7 +++++++ python/pyarrow/types.pxi | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/python/pyarrow/tests/test_types.py b/python/pyarrow/tests/test_types.py index 2a05f87615074..fef350d5de958 100644 --- a/python/pyarrow/tests/test_types.py +++ b/python/pyarrow/tests/test_types.py @@ -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'} diff --git a/python/pyarrow/types.pxi b/python/pyarrow/types.pxi index c66ac5f28d30e..02a87344c3670 100644 --- a/python/pyarrow/types.pxi +++ b/python/pyarrow/types.pxi @@ -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 @@ -3746,6 +3746,11 @@ def field(name, type=None, nullable=None, metadata=None): >>> pa.struct([field]) StructType(struct) + + A str can also be passed for the type parameter: + + >>> pa.field('key', 'int32') + pyarrow.Field """ if hasattr(name, "__arrow_c_schema__"): if type is not None: