Skip to content

Commit 0da6fd6

Browse files
authored
ARROW-35 Improve error message when schema contains an unsupported type (#45)
1 parent 1998d74 commit 0da6fd6

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

bindings/python/docs/source/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
Changes in Version 0.3.0
55
------------------------
66
- Support for `ObjectId` `bson` type.
7+
- Improve error message when schema contains an unsupported type.
78

89
Changes in Version 0.2.0
910
------------------------

bindings/python/docs/source/supported_types.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ respectively, and '_id' that is an `ObjectId`, your schema can be defined as::
3636
'f1': pyarrow.int32(),
3737
'f2': pyarrow.timestamp('ms')
3838
})
39+
40+
Unsupported data types in a schema cause a ``ValueError`` identifying the
41+
field and its data type.
42+

bindings/python/pymongoarrow/types.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,8 @@ def _get_internal_typemap(typemap):
8080
internal_typemap[fname] = internal_id
8181
except AttributeError:
8282
pass
83-
assert len(internal_typemap) == len(typemap)
83+
if fname not in internal_typemap:
84+
raise ValueError('Unsupported data type in schema for ' +
85+
f'field "{fname}" of type "{ftype}"')
86+
8487
return internal_typemap

bindings/python/test/test_bson.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from bson import encode, InvalidBSON
1717

18+
import pyarrow
1819
from pymongoarrow.context import PyMongoArrowContext
1920
from pymongoarrow.lib import process_bson_stream
2021
from pymongoarrow.schema import Schema
@@ -94,3 +95,16 @@ def test_simple(self):
9495
with self.assertRaisesRegex(
9596
InvalidBSON, "Could not read BSON document stream"):
9697
self._run_test(docs, as_dict)
98+
99+
100+
class TestUnsupportedDataType(TestBsonToArrowConversionBase):
101+
102+
def test_simple(self):
103+
104+
schema = Schema({'_id': ObjectId,
105+
'data': int64(),
106+
'title': pyarrow.string() })
107+
msg = ("Unsupported data type in schema for field " +
108+
'"title" of type "string"')
109+
with self.assertRaisesRegex(ValueError, msg):
110+
PyMongoArrowContext.from_schema(schema)

0 commit comments

Comments
 (0)