Skip to content

Commit c59080e

Browse files
committed
add system tests
1 parent 7ea142b commit c59080e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

bigframes/bigquery/_operations/json.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,10 @@ def json_value(
247247
>>> import bigframes.bigquery as bbq
248248
>>> bpd.options.display.progress_bar = None
249249
250-
>>> s = bpd.Series(['{"name": "Jakob", "age": "6"}'])
250+
>>> s = bpd.Series(['{"name": "Jakob", "age": "6"}', '{"name": "Jakob", "age": []}'])
251251
>>> bbq.json_value(s, json_path="$.age")
252252
0 6
253+
1 <NA>
253254
dtype: string
254255
255256
Args:

tests/system/small/bigquery/test_json.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,34 @@ def test_json_extract_string_array_w_invalid_series_type():
212212
bbq.json_extract_string_array(s)
213213

214214

215+
def test_json_value_from_json():
216+
s = bpd.Series(
217+
['{"a": {"b": [1, 2]}}', '{"a": {"c": 1}}', '{"a": {"b": 0}}'],
218+
dtype=dtypes.JSON_DTYPE,
219+
)
220+
actual = bbq.json_value(s, "$.a.b")
221+
expected = bpd.Series([None, None, "0"], dtype=dtypes.STRING_DTYPE)
222+
223+
pd.testing.assert_series_equal(actual.to_pandas(), expected.to_pandas())
224+
225+
226+
def test_json_value_from_string():
227+
s = bpd.Series(
228+
['{"a": {"b": [1, 2]}}', '{"a": {"c": 1}}', '{"a": {"b": 0}}'],
229+
dtype=pd.StringDtype(storage="pyarrow"),
230+
)
231+
actual = bbq.json_value(s, "$.a.b")
232+
expected = bpd.Series([None, None, "0"], dtype=dtypes.STRING_DTYPE)
233+
234+
pd.testing.assert_series_equal(actual.to_pandas(), expected.to_pandas())
235+
236+
237+
def test_json_value_w_invalid_series_type():
238+
s = bpd.Series([1, 2])
239+
with pytest.raises(TypeError):
240+
bbq.json_value(s, "$.a")
241+
242+
215243
def test_parse_json_w_invalid_series_type():
216244
s = bpd.Series([1, 2])
217245
with pytest.raises(TypeError):

0 commit comments

Comments
 (0)