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

Function fix_example_values

python/pyarrow/tests/test_orc.py:49–84  ·  view source on GitHub ↗

Fix type of expected values (as read from JSON) according to actual ORC datatype.

(actual_cols, expected_cols)

Source from the content-addressed store, hash-verified

47
48
49def fix_example_values(actual_cols, expected_cols):
50 """
51 Fix type of expected values (as read from JSON) according to
52 actual ORC datatype.
53 """
54 for name in expected_cols:
55 expected = expected_cols[name]
56 actual = actual_cols[name]
57 if (name == "map" and
58 [d.keys() == {'key', 'value'} for m in expected for d in m]):
59 # convert [{'key': k, 'value': v}, ...] to [(k, v), ...]
60 col = expected_cols[name].copy()
61 for i, m in enumerate(expected):
62 col[i] = [(d['key'], d['value']) for d in m]
63 expected_cols[name] = col
64 continue
65
66 typ = actual[0].__class__
67 if issubclass(typ, datetime.datetime):
68 # timestamp fields are represented as strings in JSON files
69 expected = pd.to_datetime(expected)
70 elif issubclass(typ, datetime.date):
71 # date fields are represented as strings in JSON files
72 expected = expected.dt.date
73 elif typ is decimal.Decimal:
74 converted_decimals = [None] * len(expected)
75 # decimal fields are represented as reals in JSON files
76 for i, (d, v) in enumerate(zip(actual, expected)):
77 if not pd.isnull(v):
78 exp = d.as_tuple().exponent
79 factor = 10 ** -exp
80 converted_decimals[i] = (
81 decimal.Decimal(round(v * factor)).scaleb(exp))
82 expected = pd.Series(converted_decimals)
83
84 expected_cols[name] = expected
85
86
87def check_example_values(orc_df, expected_df, start=None, stop=None):

Callers 1

check_example_fileFunction · 0.85

Calls 6

lenFunction · 0.85
copyMethod · 0.80
to_datetimeMethod · 0.80
keysMethod · 0.45
isnullMethod · 0.45
DecimalMethod · 0.45

Tested by

no test coverage detected