mirror of
https://github.com/apache/arrow.git
synced 2026-10-29 00:56:31 +08:00
Add decimals test
This commit is contained in:
1 parent
06c0f5f4ec
commit
43b0208a2d
5 files changed
+17
-3
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -59,12 +59,13 @@ def convert_example_file(orc_path, json_path, pickle_path):
|
||||
fix_example_values(orc_cols, json_cols)
|
||||
|
||||
print("Saving '{}'...".format(pickle_path))
|
||||
with bz2.open(pickle_path, 'wb', compresslevel=6) as f:
|
||||
pickle.dump(json_cols, f, protocol=2)
|
||||
with open(pickle_path, 'wb') as f:
|
||||
f.write(bz2.compress(pickle.dumps(json_cols, protocol=2),
|
||||
compresslevel=6))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
for name in ['TestOrcFile.test1', 'TestOrcFile.testDate1900']:
|
||||
for name in ['TestOrcFile.test1', 'TestOrcFile.testDate1900', 'decimal']:
|
||||
convert_example_file(path_for_orc_example(name),
|
||||
path_for_json_example(name),
|
||||
path_for_pickle_example(name))
|
||||
@@ -18,6 +18,7 @@
|
||||
from collections import OrderedDict
|
||||
import bz2
|
||||
import datetime
|
||||
import decimal
|
||||
import gzip
|
||||
import json
|
||||
import os
|
||||
@@ -73,6 +74,14 @@ def fix_example_values(actual_cols, expected_cols):
|
||||
# date fields are represented as strings in JSON files
|
||||
expected = [datetime.datetime.strptime(v, '%Y-%m-%d').date()
|
||||
for v in expected]
|
||||
elif typ is decimal.Decimal:
|
||||
# decimal fields are represented as reals in JSON files
|
||||
for i, (d, v) in enumerate(zip(actual, expected)):
|
||||
if v is not None:
|
||||
exp = d.as_tuple().exponent
|
||||
factor = 10 ** -exp
|
||||
expected[i] = decimal.Decimal(round(v * factor)
|
||||
).scaleb(exp)
|
||||
|
||||
expected_cols[name] = expected
|
||||
|
||||
@@ -175,3 +184,7 @@ def test_orcfile_test1_pickle():
|
||||
|
||||
def test_orcfile_dates():
|
||||
check_example_using_pickle('TestOrcFile.testDate1900')
|
||||
|
||||
|
||||
def test_orcfile_decimals():
|
||||
check_example_using_pickle('decimal')
|
||||
Reference in new issue
Block a user