File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -378,11 +378,27 @@ def literal_to_ibis_scalar(
378
378
scalar_expr = ibis .literal (literal , ibis_dtypes .float64 )
379
379
elif scalar_expr .type ().is_integer ():
380
380
scalar_expr = ibis .literal (literal , ibis_dtypes .int64 )
381
+ elif scalar_expr .type ().is_decimal ():
382
+ precision = scalar_expr .type ().precision
383
+ scale = scalar_expr .type ().scale
384
+ if (not precision or precision <= 38 ) and (not scale or scale <= 9 ):
385
+ scalar_expr = ibis .literal (
386
+ literal , ibis_dtypes .decimal (precision = 38 , scale = 9 )
387
+ )
388
+ elif precision <= 76 and scale <= 38 :
389
+ scalar_expr = ibis .literal (
390
+ literal , ibis_dtypes .decimal (precision = 76 , scale = 38 )
391
+ )
392
+ else :
393
+ raise TypeError (
394
+ "BigQuery only support decimal type with precision up to 76 and scale "
395
+ f"up to 38. Current precision: { precision } . Current scale: { scale } "
396
+ )
381
397
382
398
# TODO(bmil): support other literals that can be coerced to compatible types
383
399
if validate and (scalar_expr .type () not in BIGFRAMES_TO_IBIS .values ()):
384
400
raise ValueError (
385
- f"Literal did not coerce to a supported data type: { literal } . { constants .FEEDBACK_LINK } "
401
+ f"Literal did not coerce to a supported data type: { scalar_expr . type () } . { constants .FEEDBACK_LINK } "
386
402
)
387
403
388
404
return scalar_expr
Original file line number Diff line number Diff line change @@ -1228,6 +1228,16 @@ def test_median(scalars_dfs):
1228
1228
assert pd_min < bf_result < pd_max
1229
1229
1230
1230
1231
+ def test_numeric_literal (scalars_dfs ):
1232
+ scalars_df , _ = scalars_dfs
1233
+ col_name = "numeric_col"
1234
+ assert scalars_df [col_name ].dtype == pd .ArrowDtype (pa .decimal128 (38 , 9 ))
1235
+ bf_result = scalars_df [col_name ] - scalars_df [col_name ].median ()
1236
+ assert bf_result .size == scalars_df [col_name ].size
1237
+ # TODO(b/323387826): The precision increased by 1 unexpectedly.
1238
+ # assert bf_result.dtype == pd.ArrowDtype(pa.decimal128(38, 9))
1239
+
1240
+
1231
1241
def test_repr (scalars_dfs ):
1232
1242
scalars_df , scalars_pandas_df = scalars_dfs
1233
1243
if scalars_pandas_df .index .name != "rowindex" :
You can’t perform that action at this time.
0 commit comments