MCPcopy Create free account
hub / github.com/apache/arrow / make_random_json

Function make_random_json

python/pyarrow/tests/test_json.py:46–63  ·  view source on GitHub ↗
(num_cols=2, num_rows=10, linesep='\r\n',
                     *, extra_whitespace=False)

Source from the content-addressed store, hash-verified

44
45
46def make_random_json(num_cols=2, num_rows=10, linesep='\r\n',
47 *, extra_whitespace=False):
48 rnd = np.random.RandomState(42)
49 arr = rnd.randint(0, 1000, size=(num_cols, num_rows))
50 col_names = list(itertools.islice(generate_col_names(), num_cols))
51 lines = []
52 max_line_len = 0
53 for row in arr.T:
54 json_obj = OrderedDict([(k, int(v)) for (k, v) in zip(col_names, row)])
55 line = json.dumps(json_obj)
56 if extra_whitespace:
57 line += ' ' * rnd.randint(0, 5)
58 lines.append(line)
59 max_line_len = max(max_line_len, len(line))
60 data = linesep.join(lines).encode()
61 columns = [pa.array(col, type=pa.int64()) for col in arr]
62 expected = pa.Table.from_arrays(columns, col_names)
63 return data, max_line_len, expected
64
65
66def check_options_class_pickling(cls, pickler, **attr_values):

Callers 3

test_load_large_jsonMethod · 0.85

Calls 8

listFunction · 0.85
lenFunction · 0.85
dumpsMethod · 0.80
generate_col_namesFunction · 0.70
appendMethod · 0.45
encodeMethod · 0.45
joinMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected