Skip to content

Commit

Permalink
Add a few data type smoke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Mar 7, 2016
1 parent 47fd78e commit edb451c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion python/arrow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 4 additions & 2 deletions python/arrow/schema.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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)

Expand Down
51 changes: 51 additions & 0 deletions python/arrow/tests/test_schema.py
Original file line number Diff line number Diff line change
@@ -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<int32>'

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)"

0 comments on commit edb451c

Please sign in to comment.