diff --git a/bindings/python/pymongoarrow/types.py b/bindings/python/pymongoarrow/types.py index a788dd96..c22c325e 100644 --- a/bindings/python/pymongoarrow/types.py +++ b/bindings/python/pymongoarrow/types.py @@ -288,8 +288,8 @@ def _normalize_typeid(typeid, field_name): fields.append((sub_field_name, _normalize_typeid(sub_typeid, sub_field_name))) return struct(fields) if isinstance(typeid, list): - if len(typeid) == 0 or len(typeid) > 1: - msg = "Please provide a one datatype or struct in case of multiple datatypes in a list" + if len(typeid) != 1: + msg = f"list field in schema must contain exactly one element, not {len(typeid)}" raise ValueError(msg) return list_(_normalize_typeid(typeid[0], "0")) if _is_typeid_supported(typeid): diff --git a/bindings/python/test/test_schema.py b/bindings/python/test/test_schema.py index 2f929289..847c3e38 100644 --- a/bindings/python/test/test_schema.py +++ b/bindings/python/test/test_schema.py @@ -108,7 +108,7 @@ def test_py_list_projection(self): def test_py_list_with_multiple_fields_raises(self): - with pytest.raises(ValueError, match="Please provide a one datatype or struct in case of multiple datatypes in a list"): + with pytest.raises(ValueError, match="list field in schema must contain exactly one element, not 2"): _ = Schema( { "_id": ObjectId, @@ -118,7 +118,7 @@ def test_py_list_with_multiple_fields_raises(self): def test_py_empty_list_raises(self): - with pytest.raises(ValueError, match="Please provide a one datatype or struct in case of multiple datatypes in a list"): + with pytest.raises(ValueError, match="list field in schema must contain exactly one element, not 0"): _ = Schema( { "_id": ObjectId,