diff --git a/python/arrow/__init__.py b/python/arrow/__init__.py index 61066ba369d39..41bc8971d39c7 100644 --- a/python/arrow/__init__.py +++ b/python/arrow/__init__.py @@ -21,5 +21,5 @@ from arrow.schema import (bool_, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float_, double, string, - list_, struct, + list_, struct, field, DataType, Field, Schema) diff --git a/python/arrow/schema.pyx b/python/arrow/schema.pyx index 04e233a9e7bee..ffb159ab3d4d5 100644 --- a/python/arrow/schema.pyx +++ b/python/arrow/schema.pyx @@ -49,8 +49,7 @@ cdef class Field: self.field = self.sp_field.get() def __repr__(self): - return 'Field({0}, type={1})'.format(self.name, - self.type._type_repr()) + return 'Field({0!r}, type={1})'.format(self.name, str(self.type)) property name: @@ -72,6 +71,9 @@ cdef DataType primitive_type(LogicalType type, bint nullable=True): #------------------------------------------------------------ # Type factory functions +def field(name, type): + return Field(name, type) + def bool_(c_bool nullable=True): return primitive_type(LogicalType_BOOL, nullable) diff --git a/python/arrow/tests/test_schema.py b/python/arrow/tests/test_schema.py new file mode 100644 index 0000000000000..a89edd74a0adf --- /dev/null +++ b/python/arrow/tests/test_schema.py @@ -0,0 +1,51 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from arrow.compat import unittest +import arrow + + +class TestTypes(unittest.TestCase): + + def test_integers(self): + dtypes = ['int8', 'int16', 'int32', 'int64', + 'uint8', 'uint16', 'uint32', 'uint64'] + + for name in dtypes: + factory = getattr(arrow, name) + t = factory() + t_required = factory(False) + + assert str(t) == name + assert str(t_required) == '{0} not null'.format(name) + + def test_list(self): + value_type = arrow.int32() + list_type = arrow.list_(value_type) + assert str(list_type) == 'list' + + def test_string(self): + t = arrow.string() + assert str(t) == 'string' + + def test_field(self): + t = arrow.string() + f = arrow.field('foo', t) + + assert f.name == 'foo' + assert f.type is t + assert repr(f) == "Field('foo', type=string)"