Skip to content
This repository was archived by the owner on May 7, 2026. It is now read-only.

Commit 0420c64

Browse files
committed
modfiy polars import
1 parent dba9051 commit 0420c64

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

tests/unit/test_polars_compiler.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@
1313
# limitations under the License.
1414

1515
import pandas as pd
16-
import polars as pl
1716
import pytest
1817

18+
try:
19+
import polars as pl
20+
21+
POLARS_INSTALLED = True
22+
except ImportError:
23+
POLARS_INSTALLED = False
24+
25+
if not POLARS_INSTALLED:
26+
pytest.skip("polars is not installed", allow_module_level=True)
27+
28+
1929
import bigframes as bf
2030
import bigframes.core.compile.polars.compiler as polars_compiler
2131
import bigframes.core.nodes as nodes
@@ -48,21 +58,20 @@ def test_polars_parse_json():
4858
result_df = df.with_columns(result.alias("b")).collect()
4959
# The result of json_decode is a struct
5060
assert isinstance(result_df["b"][0], dict)
51-
assert result_df["b"][0] == {"b": 2}
61+
assert result_df["b"][0]["b"] == 2
5262

5363

54-
@pytest.mark.skip(reason="Polars does not have json_extract on string expressions")
5564
def test_polars_json_extract():
5665
"""Test JSONExtract operation in Polars compiler."""
5766
compiler = polars_compiler.PolarsExpressionCompiler()
5867
op = json_ops.JSONExtract(json_path="$.b")
5968
input_expr = pl.lit('{"a": 1, "b": "hello"}', dtype=pl.String)
6069
result = compiler.compile_op(op, input_expr)
6170

62-
df = pl.DataFrame({"a": ['{"b": "world"}']}).lazy()
71+
df = pl.DataFrame({"a": ['{"a": 1, "b": "hello"}']}).lazy()
6372
result_df = df.with_columns(result.alias("b")).collect()
64-
# json_extract returns a JSON encoded string
65-
assert result_df["b"][0] == '"world"'
73+
# json_path_match returns the raw string value
74+
assert result_df["b"][0] == "hello"
6675

6776

6877
def test_readlocal_with_json_column(polars_session):

0 commit comments

Comments
 (0)