File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -229,6 +229,10 @@ def assign_constant(
229229 value : typing .Any ,
230230 dtype : typing .Optional [bigframes .dtypes .Dtype ],
231231 ) -> ArrayValue :
232+ if pandas .isna (value ):
233+ # Need to assign a data type when value is NaN.
234+ dtype = dtype or bigframes .dtypes .DEFAULT_DTYPE
235+
232236 if destination_id in self .column_ids : # Mutate case
233237 exprs = [
234238 (
Original file line number Diff line number Diff line change @@ -605,17 +605,24 @@ def test_assign_new_column_w_loc(scalars_dfs):
605605 pd .testing .assert_frame_equal (bf_result , pd_result )
606606
607607
608- def test_assign_new_column_w_setitem (scalars_dfs ):
608+ @pytest .mark .parametrize (
609+ ("scalar" ,),
610+ [
611+ (2.1 ,),
612+ (None ,),
613+ ],
614+ )
615+ def test_assign_new_column_w_setitem (scalars_dfs , scalar ):
609616 scalars_df , scalars_pandas_df = scalars_dfs
610617 bf_df = scalars_df .copy ()
611618 pd_df = scalars_pandas_df .copy ()
612- bf_df ["new_col" ] = 2
613- pd_df ["new_col" ] = 2
619+ bf_df ["new_col" ] = scalar
620+ pd_df ["new_col" ] = scalar
614621 bf_result = bf_df .to_pandas ()
615622 pd_result = pd_df
616623
617- # Convert default pandas dtypes `int64 ` to match BigQuery DataFrames dtypes.
618- pd_result ["new_col" ] = pd_result ["new_col" ].astype ("Int64 " )
624+ # Convert default pandas dtypes `float64 ` to match BigQuery DataFrames dtypes.
625+ pd_result ["new_col" ] = pd_result ["new_col" ].astype ("Float64 " )
619626
620627 pd .testing .assert_frame_equal (bf_result , pd_result )
621628
You can’t perform that action at this time.
0 commit comments