@@ -8677,6 +8677,32 @@ def test_load_table_from_dataframe_w_nulls(self):
86778677 assert sent_config .schema == schema
86788678 assert sent_config .source_format == job .SourceFormat .PARQUET
86798679
8680+ @unittest .skipIf (pandas is None , "Requires `pandas`" )
8681+ @unittest .skipIf (pyarrow is None , "Requires `pyarrow`" )
8682+ def test_load_table_from_dataframe_w_nulls_for_required_cols (self ):
8683+ """Test that a DataFrame with null columns should throw error if
8684+ corresponding field in bigquery schema is required.
8685+
8686+ See: https://github.com/googleapis/python-bigquery/issues/1692
8687+ """
8688+ from google .cloud .bigquery .schema import SchemaField
8689+ from google .cloud .bigquery import job
8690+
8691+ client = self ._make_client ()
8692+ records = [{"name" : None , "age" : None }, {"name" : None , "age" : None }]
8693+ dataframe = pandas .DataFrame (records , columns = ["name" , "age" ])
8694+ schema = [
8695+ SchemaField ("name" , "STRING" ),
8696+ SchemaField ("age" , "INTEGER" , mode = "REQUIRED" ),
8697+ ]
8698+ job_config = job .LoadJobConfig (schema = schema )
8699+ with pytest .raises (ValueError ) as e :
8700+ client .load_table_from_dataframe (
8701+ dataframe , self .TABLE_REF , job_config = job_config , location = self .LOCATION
8702+ )
8703+
8704+ assert str (e .value ) == "required field age can not be nulls"
8705+
86808706 @unittest .skipIf (pandas is None , "Requires `pandas`" )
86818707 def test_load_table_from_dataframe_w_invaild_job_config (self ):
86828708 from google .cloud .bigquery import job
0 commit comments