19
19
class Schema :
20
20
"""A mapping of field names to data types.
21
21
22
- To create a schema, provide its constructor a mapping or an iterable
23
- containing field names and their expected types, e.g.::
22
+ To create a schema, provide its constructor a mapping of field names
23
+ to their expected types, e.g.::
24
24
25
25
schema1 = Schema({'field_1': int, 'field_2': float})
26
- schema2 = Schema([('field_1', int), ('field_2', float)])
27
26
28
- If ``schema`` is a mapping, each key must be a field name and the
29
- corresponding value must be the expected data type of the named field.
30
- If ``schema`` is an iterable, it must be comprised entirely of 2-member
31
- sub-iterables. The first member of each sub-iterable must be a field
32
- name and the second value must be the corresponding data type.
27
+ Each key in ``schema`` is a field name and its corresponding value
28
+ is the expected type of the data contained in the named field.
33
29
34
30
Data types can be specified as pyarrow type instances (e.g.
35
31
an instance of :class:`pyarrow.int64`), bson types (e.g.
@@ -42,12 +38,10 @@ def __init__(self, schema):
42
38
mapping or an iterable.
43
39
44
40
:Parameters:
45
- - `schema`: A mapping or an iterable .
41
+ - `schema`: A mapping.
46
42
"""
47
43
if isinstance (schema , abc .Mapping ):
48
44
normed = type (self )._normalize_mapping (schema )
49
- elif isinstance (schema , abc .Sequence ):
50
- normed = type (self )._normalize_sequence (schema )
51
45
else :
52
46
raise ValueError ('schema must be a mapping or sequence' )
53
47
self .typemap = normed
@@ -63,18 +57,6 @@ def _normalize_mapping(mapping):
63
57
normed [fname ] = _normalize_typeid (ftype , fname )
64
58
return normed
65
59
66
- @staticmethod
67
- def _normalize_sequence (sequence ):
68
- normed = {}
69
- for finfo in sequence :
70
- try :
71
- fname , ftype = finfo
72
- except ValueError :
73
- raise ValueError ('schema must be a sequence of 2-tuples' )
74
- else :
75
- normed [fname ] = _normalize_typeid (ftype , fname )
76
- return normed
77
-
78
60
def _get_projection (self ):
79
61
projection = {'_id' : False }
80
62
for fname , _ in self .typemap .items ():
0 commit comments