Skip to content

Commit 5c26288

Browse files
Schema can only be instantiated using mappings, not using iterables (#26)
1 parent ebc5f16 commit 5c26288

File tree

2 files changed

+6
-31
lines changed

2 files changed

+6
-31
lines changed

bindings/python/pymongoarrow/schema.py

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,13 @@
1919
class Schema:
2020
"""A mapping of field names to data types.
2121
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.::
2424
2525
schema1 = Schema({'field_1': int, 'field_2': float})
26-
schema2 = Schema([('field_1', int), ('field_2', float)])
2726
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.
3329
3430
Data types can be specified as pyarrow type instances (e.g.
3531
an instance of :class:`pyarrow.int64`), bson types (e.g.
@@ -42,12 +38,10 @@ def __init__(self, schema):
4238
mapping or an iterable.
4339
4440
:Parameters:
45-
- `schema`: A mapping or an iterable.
41+
- `schema`: A mapping.
4642
"""
4743
if isinstance(schema, abc.Mapping):
4844
normed = type(self)._normalize_mapping(schema)
49-
elif isinstance(schema, abc.Sequence):
50-
normed = type(self)._normalize_sequence(schema)
5145
else:
5246
raise ValueError('schema must be a mapping or sequence')
5347
self.typemap = normed
@@ -63,18 +57,6 @@ def _normalize_mapping(mapping):
6357
normed[fname] = _normalize_typeid(ftype, fname)
6458
return normed
6559

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-
7860
def _get_projection(self):
7961
projection = {'_id': False}
8062
for fname, _ in self.typemap.items():

bindings/python/test/test_schema.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ class TestSchema(TestCase):
2424
def test_initialization(self):
2525
dict_schema = Schema(
2626
{'field1': int, 'field2': datetime, 'field3': float})
27-
list_schema = Schema(
28-
[('field1', int), ('field2', datetime), ('field3', float)])
29-
tuple_schema = Schema(
30-
(('field1', int), ('field2', datetime), ('field3', float)))
31-
32-
self.assertEqual(dict_schema, list_schema)
33-
self.assertEqual(dict_schema, tuple_schema)
3427
self.assertEqual(
3528
dict_schema.typemap,
3629
{'field1': int64(), 'field2': timestamp('ms'),
@@ -50,7 +43,7 @@ def test_from_bson_units(self):
5043

5144
def test_from_arrow_units(self):
5245
schema = Schema(
53-
[('field1', int64()), ('field2', timestamp('s'))])
46+
{'field1': int64(), 'field2': timestamp('s')})
5447
self.assertEqual(
5548
schema.typemap,
5649
{'field1': int64(), 'field2': timestamp('s')})

0 commit comments

Comments
 (0)