@@ -46,7 +46,9 @@ def id(self):
46
46
OptionId : Type [SchemaId ] = SchemaId # enum option
47
47
Number : Type [float ] = float
48
48
49
- DataRowMetadataValue = Union [Embedding , DateTime , String , OptionId , Number ]
49
+ DataRowMetadataValue = Union [Embedding , Number , DateTime , String , OptionId ]
50
+ # primitives used in uploads
51
+ _DataRowMetadataValuePrimitives = Union [str , List , dict , float ]
50
52
51
53
52
54
class _CamelCaseMixin (BaseModel ):
@@ -84,7 +86,7 @@ class DataRowMetadataBatchResponse(_CamelCaseMixin):
84
86
# Bulk upsert values
85
87
class _UpsertDataRowMetadataInput (_CamelCaseMixin ):
86
88
schema_id : str
87
- value : Union [ str , List , dict ]
89
+ value : _DataRowMetadataValuePrimitives
88
90
89
91
90
92
# Batch of upsert values for a datarow
@@ -121,27 +123,24 @@ def __init__(self, client):
121
123
122
124
self ._raw_ontology = self ._get_ontology ()
123
125
126
+ def _build_ontology (self ):
124
127
# all fields
125
- self .fields = self ._parse_ontology ()
128
+ self .fields = self ._parse_ontology (self . _raw_ontology )
126
129
self .fields_by_id = self ._make_id_index (self .fields )
127
130
128
131
# reserved fields
129
132
self .reserved_fields : List [DataRowMetadataSchema ] = [
130
133
f for f in self .fields if f .reserved
131
134
]
132
135
self .reserved_by_id = self ._make_id_index (self .reserved_fields )
133
- self .reserved_by_name : Dict [str , DataRowMetadataSchema ] = {
134
- f .name : f for f in self .reserved_fields
135
- }
136
+ self .reserved_by_name : Dict [str , DataRowMetadataSchema ] = self ._make_name_index (self .reserved_fields )
136
137
137
138
# custom fields
138
139
self .custom_fields : List [DataRowMetadataSchema ] = [
139
140
f for f in self .fields if not f .reserved
140
141
]
141
142
self .custom_by_id = self ._make_id_index (self .custom_fields )
142
- self .custom_by_name : Dict [str , DataRowMetadataSchema ] = {
143
- f .name : f for f in self .custom_fields
144
- }
143
+ self .custom_by_name : Dict [str , DataRowMetadataSchema ] = self ._make_name_index (self .custom_fields )
145
144
146
145
@staticmethod
147
146
def _make_name_index (fields : List [DataRowMetadataSchema ]):
@@ -184,9 +183,10 @@ def _get_ontology(self) -> List[Dict[str, Any]]:
184
183
"""
185
184
return self ._client .execute (query )["customMetadataOntology" ]
186
185
187
- def _parse_ontology (self ) -> List [DataRowMetadataSchema ]:
186
+ @staticmethod
187
+ def _parse_ontology (raw_ontology ) -> List [DataRowMetadataSchema ]:
188
188
fields = []
189
- for schema in self . _raw_ontology :
189
+ for schema in raw_ontology :
190
190
schema ["uid" ] = schema .pop ("id" )
191
191
options = None
192
192
if schema .get ("options" ):
0 commit comments