File tree 2 files changed +16
-5
lines changed
2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -229,6 +229,10 @@ def assign_constant(
229
229
value : typing .Any ,
230
230
dtype : typing .Optional [bigframes .dtypes .Dtype ],
231
231
) -> 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
+
232
236
if destination_id in self .column_ids : # Mutate case
233
237
exprs = [
234
238
(
Original file line number Diff line number Diff line change @@ -605,17 +605,24 @@ def test_assign_new_column_w_loc(scalars_dfs):
605
605
pd .testing .assert_frame_equal (bf_result , pd_result )
606
606
607
607
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 ):
609
616
scalars_df , scalars_pandas_df = scalars_dfs
610
617
bf_df = scalars_df .copy ()
611
618
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
614
621
bf_result = bf_df .to_pandas ()
615
622
pd_result = pd_df
616
623
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 " )
619
626
620
627
pd .testing .assert_frame_equal (bf_result , pd_result )
621
628
You can’t perform that action at this time.
0 commit comments