Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bigframes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ def _dtype_from_string(dtype_string: str) -> typing.Optional[Dtype]:

def infer_literal_type(literal) -> typing.Optional[Dtype]:
# Maybe also normalize literal to canonical python representation to remove this burden from compilers?
if isinstance(literal, pa.Scalar):
return arrow_dtype_to_bigframes_dtype(literal.type)
if pd.api.types.is_list_like(literal):
element_types = [infer_literal_type(i) for i in literal]
common_type = lcd_type(*element_types)
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/core/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,15 @@ def test_literal_to_ibis_scalar_throws_on_incompatible_literal():
ValueError,
):
bigframes.core.compile.ibis_types.literal_to_ibis_scalar({"mykey": "myval"})


@pytest.mark.parametrize(
["scalar", "expected_dtype"],
[
(pa.scalar(1_000_000_000, type=pa.int64()), bigframes.dtypes.INT_DTYPE),
(pa.scalar(True, type=pa.bool_()), bigframes.dtypes.BOOL_DTYPE),
(pa.scalar("hello", type=pa.string()), bigframes.dtypes.STRING_DTYPE),
Comment thread
tswast marked this conversation as resolved.
],
)
def test_infer_literal_type_arrow_scalar(scalar, expected_dtype):
assert bigframes.dtypes.infer_literal_type(scalar) == expected_dtype