22
22
import bigframes .pandas as bpd
23
23
24
24
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
-
32
25
@pytest .mark .parametrize (
33
26
("json_path" , "expected_json" ),
34
27
[
@@ -39,12 +32,14 @@ def use_large_query_path():
39
32
def test_json_set_at_json_path (json_path , expected_json ):
40
33
original_json = ['{"a": {"b": {"c": "tester", "d": []}}}' ]
41
34
s = bpd .Series (original_json , dtype = dtypes .JSON_DTYPE )
42
- actual = bbq .json_set (s , json_path_value_pairs = [(json_path , 10 )])
43
35
36
+ actual = bbq .json_set (s , json_path_value_pairs = [(json_path , 10 )])
44
37
expected = bpd .Series (expected_json , dtype = dtypes .JSON_DTYPE )
38
+
39
+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
45
40
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 ),
48
43
)
49
44
50
45
@@ -63,11 +58,12 @@ def test_json_set_at_json_value_type(json_value, expected_json):
63
58
original_json = ['{"a": {"b": "dev"}}' , '{"a": {"b": [1, 2]}}' ]
64
59
s = bpd .Series (original_json , dtype = dtypes .JSON_DTYPE )
65
60
actual = bbq .json_set (s , json_path_value_pairs = [("$.a.b" , json_value )])
66
-
67
61
expected = bpd .Series (expected_json , dtype = dtypes .JSON_DTYPE )
62
+
63
+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
68
64
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 ),
71
67
)
72
68
73
69
@@ -80,18 +76,14 @@ def test_json_set_w_more_pairs():
80
76
81
77
expected_json = ['{"a": 3, "b": 2}' , '{"a": 4, "b": 2}' , '{"a": 5, "b": 2, "c": 1}' ]
82
78
expected = bpd .Series (expected_json , dtype = dtypes .JSON_DTYPE )
79
+
80
+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
83
81
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 ),
86
84
)
87
85
88
86
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
-
95
87
def test_json_set_w_invalid_value_type ():
96
88
s = bpd .Series (['{"a": 10}' ], dtype = dtypes .JSON_DTYPE )
97
89
with pytest .raises (TypeError ):
@@ -119,11 +111,13 @@ def test_json_extract_from_json():
119
111
['{"a": {"b": [1, 2]}}' , '{"a": {"c": 1}}' , '{"a": {"b": 0}}' ],
120
112
dtype = dtypes .JSON_DTYPE ,
121
113
)
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
124
118
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 ) ,
127
121
)
128
122
129
123
@@ -134,9 +128,11 @@ def test_json_extract_from_string():
134
128
)
135
129
actual = bbq .json_extract (s , "$.a.b" )
136
130
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
137
133
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 ),
140
136
)
141
137
142
138
@@ -169,9 +165,10 @@ def test_json_extract_array_from_json():
169
165
expected .index .name = None
170
166
expected .name = None
171
167
168
+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
172
169
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 ),
175
172
)
176
173
177
174
@@ -185,9 +182,11 @@ def test_json_extract_array_from_json_strings():
185
182
[['"ab"' , '"2"' , '"3 xy"' ], [], ['"4"' , '"5"' ], None ],
186
183
dtype = pd .ArrowDtype (pa .list_ (pa .string ())),
187
184
)
185
+
186
+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
188
187
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 ),
191
190
)
192
191
193
192
@@ -201,9 +200,11 @@ def test_json_extract_array_from_json_array_strings():
201
200
[["1" , "2" , "3" ], [], ["4" , "5" ]],
202
201
dtype = pd .ArrowDtype (pa .list_ (pa .string ())),
203
202
)
203
+
204
+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
204
205
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 ),
207
208
)
208
209
209
210
@@ -217,37 +218,45 @@ def test_json_extract_string_array_from_json_strings():
217
218
s = bpd .Series (['{"a": ["ab", "2", "3 xy"]}' , '{"a": []}' , '{"a": ["4","5"]}' ])
218
219
actual = bbq .json_extract_string_array (s , "$.a" )
219
220
expected = bpd .Series ([["ab" , "2" , "3 xy" ], [], ["4" , "5" ]])
221
+
222
+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
220
223
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 ),
223
226
)
224
227
225
228
226
229
def test_json_extract_string_array_from_array_strings ():
227
230
s = bpd .Series (["[1, 2, 3]" , "[]" , "[4,5]" ])
228
231
actual = bbq .json_extract_string_array (s )
229
232
expected = bpd .Series ([["1" , "2" , "3" ], [], ["4" , "5" ]])
233
+
234
+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
230
235
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 ),
233
238
)
234
239
235
240
236
241
def test_json_extract_string_array_as_float_array_from_array_strings ():
237
242
s = bpd .Series (["[1, 2.5, 3]" , "[]" , "[4,5]" ])
238
243
actual = bbq .json_extract_string_array (s , value_dtype = dtypes .FLOAT_DTYPE )
239
244
expected = bpd .Series ([[1 , 2.5 , 3 ], [], [4 , 5 ]])
245
+
246
+ # TODO(b/401630655): JSON is not compatible with allow_large_results=False
240
247
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 ),
243
250
)
244
251
245
252
246
253
def test_json_extract_string_array_w_invalid_series_type ():
254
+ s = bpd .Series ([1 , 2 ])
247
255
with pytest .raises (TypeError ):
248
- bbq .json_extract_string_array (bpd . Series ([ 1 , 2 ]) )
256
+ bbq .json_extract_string_array (s )
249
257
250
258
251
259
def test_parse_json_w_invalid_series_type ():
260
+ s = bpd .Series ([1 , 2 ])
252
261
with pytest .raises (TypeError ):
253
- bbq .parse_json (bpd . Series ([ 1 , 2 ]) )
262
+ bbq .parse_json (s )
0 commit comments