/
usr
/
local
/
lib64
/
python3.6
/
site-packages
/
pyarrow
/
tests
/
/usr/local/lib64/python3.6/site-packages/pyarrow/tests
mkdir
upload
Name
Size
Mode
Actions
data/
-
0755
rm
parquet/
-
0755
rm
__pycache__/
-
0755
rm
arrow_7980.py
1094
0644
edit
dl
rm
bound_function_visit_strings.pyx
2047
0644
edit
dl
rm
conftest.py
7982
0644
edit
dl
rm
deserialize_buffer.py
961
0644
edit
dl
rm
pandas_examples.py
5115
0644
edit
dl
rm
pandas_threaded_import.py
1429
0644
edit
dl
rm
pyarrow_cython_example.pyx
1951
0644
edit
dl
rm
strategies.py
12525
0644
edit
dl
rm
test_adhoc_memory_leak.py
1410
0644
edit
dl
rm
test_array.py
100157
0644
edit
dl
rm
test_builder.py
2184
0644
edit
dl
rm
test_cffi.py
13090
0644
edit
dl
rm
test_compute.py
83551
0644
edit
dl
rm
test_convert_builtin.py
71768
0644
edit
dl
rm
test_csv.py
68943
0644
edit
dl
rm
test_cuda.py
27863
0644
edit
dl
rm
test_cuda_numba_interop.py
8730
0644
edit
dl
rm
test_cython.py
5948
0644
edit
dl
rm
test_dataset.py
143023
0644
edit
dl
rm
test_deprecations.py
891
0644
edit
dl
rm
test_extension_type.py
24437
0644
edit
dl
rm
test_feather.py
23209
0644
edit
dl
rm
test_filesystem.py
2106
0644
edit
dl
rm
test_flight.py
73715
0644
edit
dl
rm
test_fs.py
54133
0644
edit
dl
rm
test_gandiva.py
14385
0644
edit
dl
rm
test_hdfs.py
13452
0644
edit
dl
rm
test_io.py
53066
0644
edit
dl
rm
test_ipc.py
31267
0644
edit
dl
rm
test_json.py
11325
0644
edit
dl
rm
test_jvm.py
15471
0644
edit
dl
rm
test_memory.py
4928
0644
edit
dl
rm
test_misc.py
4927
0644
edit
dl
rm
test_orc.py
9221
0644
edit
dl
rm
test_pandas.py
157909
0644
edit
dl
rm
test_plasma.py
44011
0644
edit
dl
rm
test_plasma_tf_op.py
3523
0644
edit
dl
rm
test_scalars.py
21074
0644
edit
dl
rm
test_schema.py
21282
0644
edit
dl
rm
test_serialization.py
42026
0644
edit
dl
rm
test_serialization_deprecated.py
1775
0644
edit
dl
rm
test_sparse_tensor.py
17436
0644
edit
dl
rm
test_strategies.py
1739
0644
edit
dl
rm
test_table.py
53168
0644
edit
dl
rm
test_tensor.py
6270
0644
edit
dl
rm
test_types.py
31487
0644
edit
dl
rm
test_util.py
1791
0644
edit
dl
rm
util.py
9011
0644
edit
dl
rm
__init__.py
0
0644
edit
dl
rm
Edit:
/usr/local/lib64/python3.6/site-packages/pyarrow/tests/test_json.py
(11325B)
# Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. from collections import OrderedDict import io import itertools import json import string import unittest import numpy as np import pytest import pyarrow as pa from pyarrow.json import read_json, ReadOptions, ParseOptions def generate_col_names(): # 'a', 'b'... 'z', then 'aa', 'ab'... letters = string.ascii_lowercase yield from letters for first in letters: for second in letters: yield first + second def make_random_json(num_cols=2, num_rows=10, linesep='\r\n'): arr = np.random.RandomState(42).randint(0, 1000, size=(num_cols, num_rows)) col_names = list(itertools.islice(generate_col_names(), num_cols)) lines = [] for row in arr.T: json_obj = OrderedDict([(k, int(v)) for (k, v) in zip(col_names, row)]) lines.append(json.dumps(json_obj)) data = linesep.join(lines).encode() columns = [pa.array(col, type=pa.int64()) for col in arr] expected = pa.Table.from_arrays(columns, col_names) return data, expected def test_read_options(): cls = ReadOptions opts = cls() assert opts.block_size > 0 opts.block_size = 12345 assert opts.block_size == 12345 assert opts.use_threads is True opts.use_threads = False assert opts.use_threads is False opts = cls(block_size=1234, use_threads=False) assert opts.block_size == 1234 assert opts.use_threads is False def test_parse_options(): cls = ParseOptions opts = cls() assert opts.newlines_in_values is False assert opts.explicit_schema is None opts.newlines_in_values = True assert opts.newlines_in_values is True schema = pa.schema([pa.field('foo', pa.int32())]) opts.explicit_schema = schema assert opts.explicit_schema == schema assert opts.unexpected_field_behavior == "infer" for value in ["ignore", "error", "infer"]: opts.unexpected_field_behavior = value assert opts.unexpected_field_behavior == value with pytest.raises(ValueError): opts.unexpected_field_behavior = "invalid-value" class BaseTestJSONRead: def read_bytes(self, b, **kwargs): return self.read_json(pa.py_buffer(b), **kwargs) def check_names(self, table, names): assert table.num_columns == len(names) assert [c.name for c in table.columns] == names def test_file_object(self): data = b'{"a": 1, "b": 2}\n' expected_data = {'a': [1], 'b': [2]} bio = io.BytesIO(data) table = self.read_json(bio) assert table.to_pydict() == expected_data # Text files not allowed sio = io.StringIO(data.decode()) with pytest.raises(TypeError): self.read_json(sio) def test_block_sizes(self): rows = b'{"a": 1}\n{"a": 2}\n{"a": 3}' read_options = ReadOptions() parse_options = ParseOptions() for data in [rows, rows + b'\n']: for newlines_in_values in [False, True]: parse_options.newlines_in_values = newlines_in_values read_options.block_size = 4 with pytest.raises(ValueError, match="try to increase block size"): self.read_bytes(data, read_options=read_options, parse_options=parse_options) # Validate reader behavior with various block sizes. # There used to be bugs in this area. for block_size in range(9, 20): read_options.block_size = block_size table = self.read_bytes(data, read_options=read_options, parse_options=parse_options) assert table.to_pydict() == {'a': [1, 2, 3]} def test_no_newline_at_end(self): rows = b'{"a": 1,"b": 2, "c": 3}\n{"a": 4,"b": 5, "c": 6}' table = self.read_bytes(rows) assert table.to_pydict() == { 'a': [1, 4], 'b': [2, 5], 'c': [3, 6], } def test_simple_ints(self): # Infer integer columns rows = b'{"a": 1,"b": 2, "c": 3}\n{"a": 4,"b": 5, "c": 6}\n' table = self.read_bytes(rows) schema = pa.schema([('a', pa.int64()), ('b', pa.int64()), ('c', pa.int64())]) assert table.schema == schema assert table.to_pydict() == { 'a': [1, 4], 'b': [2, 5], 'c': [3, 6], } def test_simple_varied(self): # Infer various kinds of data rows = (b'{"a": 1,"b": 2, "c": "3", "d": false}\n' b'{"a": 4.0, "b": -5, "c": "foo", "d": true}\n') table = self.read_bytes(rows) schema = pa.schema([('a', pa.float64()), ('b', pa.int64()), ('c', pa.string()), ('d', pa.bool_())]) assert table.schema == schema assert table.to_pydict() == { 'a': [1.0, 4.0], 'b': [2, -5], 'c': ["3", "foo"], 'd': [False, True], } def test_simple_nulls(self): # Infer various kinds of data, with nulls rows = (b'{"a": 1, "b": 2, "c": null, "d": null, "e": null}\n' b'{"a": null, "b": -5, "c": "foo", "d": null, "e": true}\n' b'{"a": 4.5, "b": null, "c": "nan", "d": null,"e": false}\n') table = self.read_bytes(rows) schema = pa.schema([('a', pa.float64()), ('b', pa.int64()), ('c', pa.string()), ('d', pa.null()), ('e', pa.bool_())]) assert table.schema == schema assert table.to_pydict() == { 'a': [1.0, None, 4.5], 'b': [2, -5, None], 'c': [None, "foo", "nan"], 'd': [None, None, None], 'e': [None, True, False], } def test_empty_lists(self): # ARROW-10955: Infer list(null) rows = b'{"a": []}' table = self.read_bytes(rows) schema = pa.schema([('a', pa.list_(pa.null()))]) assert table.schema == schema assert table.to_pydict() == {'a': [[]]} def test_empty_rows(self): rows = b'{}\n{}\n' table = self.read_bytes(rows) schema = pa.schema([]) assert table.schema == schema assert table.num_columns == 0 assert table.num_rows == 2 def test_reconcile_accross_blocks(self): # ARROW-12065: reconciling inferred types accross blocks first_row = b'{ }\n' read_options = ReadOptions(block_size=len(first_row)) for next_rows, expected_pylist in [ (b'{"a": 0}', [None, 0]), (b'{"a": []}', [None, []]), (b'{"a": []}\n{"a": [[1]]}', [None, [], [[1]]]), (b'{"a": {}}', [None, {}]), (b'{"a": {}}\n{"a": {"b": {"c": 1}}}', [None, {"b": None}, {"b": {"c": 1}}]), ]: table = self.read_bytes(first_row + next_rows, read_options=read_options) expected = {"a": expected_pylist} assert table.to_pydict() == expected # Check that the issue was exercised assert table.column("a").num_chunks > 1 def test_explicit_schema_with_unexpected_behaviour(self): # infer by default rows = (b'{"foo": "bar", "num": 0}\n' b'{"foo": "baz", "num": 1}\n') schema = pa.schema([ ('foo', pa.binary()) ]) opts = ParseOptions(explicit_schema=schema) table = self.read_bytes(rows, parse_options=opts) assert table.schema == pa.schema([ ('foo', pa.binary()), ('num', pa.int64()) ]) assert table.to_pydict() == { 'foo': [b'bar', b'baz'], 'num': [0, 1], } # ignore the unexpected fields opts = ParseOptions(explicit_schema=schema, unexpected_field_behavior="ignore") table = self.read_bytes(rows, parse_options=opts) assert table.schema == pa.schema([ ('foo', pa.binary()), ]) assert table.to_pydict() == { 'foo': [b'bar', b'baz'], } # raise error opts = ParseOptions(explicit_schema=schema, unexpected_field_behavior="error") with pytest.raises(pa.ArrowInvalid, match="JSON parse error: unexpected field"): self.read_bytes(rows, parse_options=opts) def test_small_random_json(self): data, expected = make_random_json(num_cols=2, num_rows=10) table = self.read_bytes(data) assert table.schema == expected.schema assert table.equals(expected) assert table.to_pydict() == expected.to_pydict() def test_stress_block_sizes(self): # Test a number of small block sizes to stress block stitching data_base, expected = make_random_json(num_cols=2, num_rows=100) read_options = ReadOptions() parse_options = ParseOptions() for data in [data_base, data_base.rstrip(b'\r\n')]: for newlines_in_values in [False, True]: parse_options.newlines_in_values = newlines_in_values for block_size in [22, 23, 37]: read_options.block_size = block_size table = self.read_bytes(data, read_options=read_options, parse_options=parse_options) assert table.schema == expected.schema if not table.equals(expected): # Better error output assert table.to_pydict() == expected.to_pydict() class TestSerialJSONRead(BaseTestJSONRead, unittest.TestCase): def read_json(self, *args, **kwargs): read_options = kwargs.setdefault('read_options', ReadOptions()) read_options.use_threads = False table = read_json(*args, **kwargs) table.validate(full=True) return table class TestParallelJSONRead(BaseTestJSONRead, unittest.TestCase): def read_json(self, *args, **kwargs): read_options = kwargs.setdefault('read_options', ReadOptions()) read_options.use_threads = True table = read_json(*args, **kwargs) table.validate(full=True) return table
Save
cmd:
run