Skip to content

Commit 7fcd4b6

Browse files
I am working on adding support for pyarrow.Scalar to infer_literal_method.
1 parent 7e03252 commit 7fcd4b6

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

bigframes/dtypes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,8 @@ def _dtype_from_string(dtype_string: str) -> typing.Optional[Dtype]:
659659

660660
def infer_literal_type(literal) -> typing.Optional[Dtype]:
661661
# Maybe also normalize literal to canonical python representation to remove this burden from compilers?
662+
if isinstance(literal, pa.Scalar):
663+
return arrow_dtype_to_bigframes_dtype(literal.type)
662664
if pd.api.types.is_list_like(literal):
663665
element_types = [infer_literal_type(i) for i in literal]
664666
common_type = lcd_type(*element_types)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"matplotlib >=3.7.1",
6262
"db-dtypes >=1.4.2",
6363
# For vendored ibis-framework.
64+
"ibis-framework==6.2.0",
6465
"atpublic>=2.3,<6",
6566
"python-dateutil>=2.8.2,<3",
6667
"pytz>=2022.7",

tests/unit/core/test_dtypes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,15 @@ def test_literal_to_ibis_scalar_throws_on_incompatible_literal():
272272
ValueError,
273273
):
274274
bigframes.core.compile.ibis_types.literal_to_ibis_scalar({"mykey": "myval"})
275+
276+
277+
@pytest.mark.parametrize(
278+
["scalar", "expected_dtype"],
279+
[
280+
(pa.scalar(1_000_000_000, type=pa.int64()), bigframes.dtypes.INT_DTYPE),
281+
(pa.scalar(True, type=pa.bool_()), bigframes.dtypes.BOOL_DTYPE),
282+
(pa.scalar("hello", type=pa.string()), bigframes.dtypes.STRING_DTYPE),
283+
],
284+
)
285+
def test_infer_literal_type_arrow_scalar(scalar, expected_dtype):
286+
assert bigframes.dtypes.infer_literal_type(scalar) == expected_dtype

0 commit comments

Comments
 (0)