2222import bigframes .pandas as bpd
2323
2424
25- @pytest .fixture (scope = "module" , autouse = True )
26- def use_large_query_path ():
27- # b/401630655
28- with bpd .option_context ("bigquery.allow_large_results" , True ):
29- yield
30-
31-
3225@pytest .mark .parametrize (
3326 ("json_path" , "expected_json" ),
3427 [
@@ -39,12 +32,14 @@ def use_large_query_path():
3932def test_json_set_at_json_path (json_path , expected_json ):
4033 original_json = ['{"a": {"b": {"c": "tester", "d": []}}}' ]
4134 s = bpd .Series (original_json , dtype = dtypes .JSON_DTYPE )
42- actual = bbq .json_set (s , json_path_value_pairs = [(json_path , 10 )])
4335
36+ actual = bbq .json_set (s , json_path_value_pairs = [(json_path , 10 )])
4437 expected = bpd .Series (expected_json , dtype = dtypes .JSON_DTYPE )
38+
39+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
4540 pd .testing .assert_series_equal (
46- actual .to_pandas (),
47- expected .to_pandas (),
41+ actual .to_pandas (allow_large_results = True ),
42+ expected .to_pandas (allow_large_results = True ),
4843 )
4944
5045
@@ -63,11 +58,12 @@ def test_json_set_at_json_value_type(json_value, expected_json):
6358 original_json = ['{"a": {"b": "dev"}}' , '{"a": {"b": [1, 2]}}' ]
6459 s = bpd .Series (original_json , dtype = dtypes .JSON_DTYPE )
6560 actual = bbq .json_set (s , json_path_value_pairs = [("$.a.b" , json_value )])
66-
6761 expected = bpd .Series (expected_json , dtype = dtypes .JSON_DTYPE )
62+
63+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
6864 pd .testing .assert_series_equal (
69- actual .to_pandas (),
70- expected .to_pandas (),
65+ actual .to_pandas (allow_large_results = True ),
66+ expected .to_pandas (allow_large_results = True ),
7167 )
7268
7369
@@ -80,18 +76,14 @@ def test_json_set_w_more_pairs():
8076
8177 expected_json = ['{"a": 3, "b": 2}' , '{"a": 4, "b": 2}' , '{"a": 5, "b": 2, "c": 1}' ]
8278 expected = bpd .Series (expected_json , dtype = dtypes .JSON_DTYPE )
79+
80+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
8381 pd .testing .assert_series_equal (
84- actual .to_pandas (),
85- expected .to_pandas (),
82+ actual .to_pandas (allow_large_results = True ),
83+ expected .to_pandas (allow_large_results = True ),
8684 )
8785
8886
89- def test_json_set_w_invalid_json_path_value_pairs ():
90- s = bpd .Series (['{"a": 10}' ], dtype = dtypes .JSON_DTYPE )
91- with pytest .raises (ValueError ):
92- bbq .json_set (s , json_path_value_pairs = [("$.a" , 1 , 100 )]) # type: ignore
93-
94-
9587def test_json_set_w_invalid_value_type ():
9688 s = bpd .Series (['{"a": 10}' ], dtype = dtypes .JSON_DTYPE )
9789 with pytest .raises (TypeError ):
@@ -119,11 +111,13 @@ def test_json_extract_from_json():
119111 ['{"a": {"b": [1, 2]}}' , '{"a": {"c": 1}}' , '{"a": {"b": 0}}' ],
120112 dtype = dtypes .JSON_DTYPE ,
121113 )
122- actual = bbq .json_extract (s , "$.a.b" ).to_pandas ()
123- expected = bpd .Series (["[1, 2]" , None , "0" ], dtype = dtypes .JSON_DTYPE ).to_pandas ()
114+ actual = bbq .json_extract (s , "$.a.b" )
115+ expected = bpd .Series (["[1, 2]" , None , "0" ], dtype = dtypes .JSON_DTYPE )
116+
117+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
124118 pd .testing .assert_series_equal (
125- actual ,
126- expected ,
119+ actual . to_pandas ( allow_large_results = True ) ,
120+ expected . to_pandas ( allow_large_results = True ) ,
127121 )
128122
129123
@@ -134,9 +128,11 @@ def test_json_extract_from_string():
134128 )
135129 actual = bbq .json_extract (s , "$.a.b" )
136130 expected = bpd .Series (["[1,2]" , None , "0" ], dtype = pd .StringDtype (storage = "pyarrow" ))
131+
132+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
137133 pd .testing .assert_series_equal (
138- actual .to_pandas (),
139- expected .to_pandas (),
134+ actual .to_pandas (allow_large_results = True ),
135+ expected .to_pandas (allow_large_results = True ),
140136 )
141137
142138
@@ -169,9 +165,10 @@ def test_json_extract_array_from_json():
169165 expected .index .name = None
170166 expected .name = None
171167
168+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
172169 pd .testing .assert_series_equal (
173- actual .to_pandas (),
174- expected .to_pandas (),
170+ actual .to_pandas (allow_large_results = True ),
171+ expected .to_pandas (allow_large_results = True ),
175172 )
176173
177174
@@ -185,9 +182,11 @@ def test_json_extract_array_from_json_strings():
185182 [['"ab"' , '"2"' , '"3 xy"' ], [], ['"4"' , '"5"' ], None ],
186183 dtype = pd .ArrowDtype (pa .list_ (pa .string ())),
187184 )
185+
186+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
188187 pd .testing .assert_series_equal (
189- actual .to_pandas (),
190- expected .to_pandas (),
188+ actual .to_pandas (allow_large_results = True ),
189+ expected .to_pandas (allow_large_results = True ),
191190 )
192191
193192
@@ -201,9 +200,11 @@ def test_json_extract_array_from_json_array_strings():
201200 [["1" , "2" , "3" ], [], ["4" , "5" ]],
202201 dtype = pd .ArrowDtype (pa .list_ (pa .string ())),
203202 )
203+
204+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
204205 pd .testing .assert_series_equal (
205- actual .to_pandas (),
206- expected .to_pandas (),
206+ actual .to_pandas (allow_large_results = True ),
207+ expected .to_pandas (allow_large_results = True ),
207208 )
208209
209210
@@ -217,37 +218,45 @@ def test_json_extract_string_array_from_json_strings():
217218 s = bpd .Series (['{"a": ["ab", "2", "3 xy"]}' , '{"a": []}' , '{"a": ["4","5"]}' ])
218219 actual = bbq .json_extract_string_array (s , "$.a" )
219220 expected = bpd .Series ([["ab" , "2" , "3 xy" ], [], ["4" , "5" ]])
221+
222+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
220223 pd .testing .assert_series_equal (
221- actual .to_pandas (),
222- expected .to_pandas (),
224+ actual .to_pandas (allow_large_results = True ),
225+ expected .to_pandas (allow_large_results = True ),
223226 )
224227
225228
226229def test_json_extract_string_array_from_array_strings ():
227230 s = bpd .Series (["[1, 2, 3]" , "[]" , "[4,5]" ])
228231 actual = bbq .json_extract_string_array (s )
229232 expected = bpd .Series ([["1" , "2" , "3" ], [], ["4" , "5" ]])
233+
234+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
230235 pd .testing .assert_series_equal (
231- actual .to_pandas (),
232- expected .to_pandas (),
236+ actual .to_pandas (allow_large_results = True ),
237+ expected .to_pandas (allow_large_results = True ),
233238 )
234239
235240
236241def test_json_extract_string_array_as_float_array_from_array_strings ():
237242 s = bpd .Series (["[1, 2.5, 3]" , "[]" , "[4,5]" ])
238243 actual = bbq .json_extract_string_array (s , value_dtype = dtypes .FLOAT_DTYPE )
239244 expected = bpd .Series ([[1 , 2.5 , 3 ], [], [4 , 5 ]])
245+
246+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
240247 pd .testing .assert_series_equal (
241- actual .to_pandas (),
242- expected .to_pandas (),
248+ actual .to_pandas (allow_large_results = True ),
249+ expected .to_pandas (allow_large_results = True ),
243250 )
244251
245252
246253def test_json_extract_string_array_w_invalid_series_type ():
254+ s = bpd .Series ([1 , 2 ])
247255 with pytest .raises (TypeError ):
248- bbq .json_extract_string_array (bpd . Series ([ 1 , 2 ]) )
256+ bbq .json_extract_string_array (s )
249257
250258
251259def test_parse_json_w_invalid_series_type ():
260+ s = bpd .Series ([1 , 2 ])
252261 with pytest .raises (TypeError ):
253- bbq .parse_json (bpd . Series ([ 1 , 2 ]) )
262+ bbq .parse_json (s )
0 commit comments