@@ -167,9 +167,25 @@ def dtype_to_bigquery_field(name, dtype) -> Optional[schema.SchemaField]:
167167
168168
169169def value_to_bigquery_field (
170- name , value , default_type = None
170+ name : str , value : Any , default_type : Optional [ str ] = None
171171) -> Optional [schema .SchemaField ]:
172- # There are no non-null values, so assume the default type.
172+ """Infers the BigQuery schema field type from a single value.
173+
174+ Args:
175+ name:
176+ The name of the field.
177+ value:
178+ The value to infer the type from. If None, the default type is used
179+ if available.
180+ default_type:
181+ The default field type. Defaults to None.
182+
183+ Returns:
184+ The schema field, or None if a type cannot be inferred.
185+ """
186+
187+ # Set the SchemaField datatype to the given default_type if the value
188+ # being assessed is None.
173189 if value is None :
174190 return schema .SchemaField (name , default_type )
175191
@@ -207,12 +223,30 @@ def value_to_bigquery_field(
207223
208224
209225def values_to_bigquery_field (
210- name , values , default_type = "STRING"
226+ name : str , values : Any , default_type : str = "STRING"
211227) -> Optional [schema .SchemaField ]:
228+ """Infers the BigQuery schema field type from a list of values.
229+
230+ This function iterates through the given values to determine the
231+ corresponding schema field type.
232+
233+ Args:
234+ name:
235+ The name of the field.
236+ values:
237+ An iterable of values to infer the type from. If all the values
238+ are None or the iterable is empty, the function returns None.
239+ default_type:
240+ The default field type to use if a specific type cannot be
241+ determined from the values. Defaults to "STRING".
242+
243+ Returns:
244+ The schema field, or None if a type cannot be inferred.
245+ """
212246 value = pandas_gbq .core .pandas .first_valid (values )
213247
214- # All NULL, type not determinable by this method. Return None so we can try
215- # some other methods.
248+ # All values came back as NULL, thus type not determinable by this method.
249+ # Return None so we can try other methods.
216250 if value is None :
217251 return None
218252
0 commit comments