Skip to content

Commit 5e981f9

Browse files
committed
exclude tests if pa.json_ is not available
1 parent 7595df1 commit 5e981f9

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

samples/snippets/type_system_test.py

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -80,46 +80,48 @@ def test_type_system_examples() -> None:
8080
check_index_type=False,
8181
)
8282

83-
# [START bigquery_dataframes_type_system_mixed_json]
84-
import db_dtypes
85-
import pandas as pd
86-
import pyarrow as pa
87-
88-
import bigframes.pandas as bpd
89-
90-
list_data = [
91-
[{"key": "1"}],
92-
[{"key": None}],
93-
[{"key": '["1","3","5"]'}],
94-
[{"key": '{"a":1,"b":["x","y"],"c":{"x":[],"z":false}}'}],
95-
]
96-
pa_array = pa.array(list_data, type=pa.list_(pa.struct([("key", pa.string())])))
97-
bpd.Series(
98-
pd.arrays.ArrowExtensionArray(pa_array),
99-
dtype=pd.ArrowDtype(
100-
pa.list_(pa.struct([("key", pa.json_(pa.string()))])),
101-
),
102-
)
103-
# 0 [{'key': '1'}]
104-
# 1 [{'key': None}]
105-
# 2 [{'key': '["1","3","5"]'}]
106-
# 3 [{'key': '{"a":1,"b":["x","y"],"c":{"x":[],"z"...
107-
# [END bigquery_dataframes_type_system_mixed_json]
108-
pandas.testing.assert_series_equal(
83+
assert pa.__version__.startswith("19.") or pa.__version__.startswith("2")
84+
if hasattr(pa, "JsonType"):
85+
# [START bigquery_dataframes_type_system_mixed_json]
86+
import db_dtypes
87+
import pandas as pd
88+
import pyarrow as pa
89+
90+
import bigframes.pandas as bpd
91+
92+
list_data = [
93+
[{"key": "1"}],
94+
[{"key": None}],
95+
[{"key": '["1","3","5"]'}],
96+
[{"key": '{"a":1,"b":["x","y"],"c":{"x":[],"z":false}}'}],
97+
]
98+
pa_array = pa.array(list_data, type=pa.list_(pa.struct([("key", pa.string())])))
10999
bpd.Series(
110100
pd.arrays.ArrowExtensionArray(pa_array),
111101
dtype=pd.ArrowDtype(
112102
pa.list_(pa.struct([("key", pa.json_(pa.string()))])),
113103
),
114-
).to_pandas(),
115-
pd.Series(
116-
pd.arrays.ArrowExtensionArray(pa_array),
117-
dtype=pd.ArrowDtype(
118-
pa.list_(pa.struct([("key", db_dtypes.JSONArrowType())])),
104+
)
105+
# 0 [{'key': '1'}]
106+
# 1 [{'key': None}]
107+
# 2 [{'key': '["1","3","5"]'}]
108+
# 3 [{'key': '{"a":1,"b":["x","y"],"c":{"x":[],"z"...
109+
# [END bigquery_dataframes_type_system_mixed_json]
110+
pandas.testing.assert_series_equal(
111+
bpd.Series(
112+
pd.arrays.ArrowExtensionArray(pa_array),
113+
dtype=pd.ArrowDtype(
114+
pa.list_(pa.struct([("key", pa.json_(pa.string()))])),
115+
),
116+
).to_pandas(),
117+
pd.Series(
118+
pd.arrays.ArrowExtensionArray(pa_array),
119+
dtype=pd.ArrowDtype(
120+
pa.list_(pa.struct([("key", db_dtypes.JSONArrowType())])),
121+
),
119122
),
120-
),
121-
check_index_type=False,
122-
)
123+
check_index_type=False,
124+
)
123125

124126
# [START bigquery_dataframes_type_system_load_timedelta]
125127
import pandas as pd

0 commit comments

Comments
 (0)