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

Function test_table_safe_casting

python/pyarrow/tests/test_table.py:2208–2233  ·  view source on GitHub ↗
(cls)

Source from the content-addressed store, hash-verified

2206 ]
2207)
2208def test_table_safe_casting(cls):
2209 data = [
2210 pa.array(range(5), type=pa.int64()),
2211 pa.array([-10, -5, 0, 5, 10], type=pa.int32()),
2212 pa.array([1.0, 2.0, 3.0, 4.0, 5.0], type=pa.float64()),
2213 pa.array(['ab', 'bc', 'cd', 'de', 'ef'], type=pa.string())
2214 ]
2215 table = cls.from_arrays(data, names=tuple('abcd'))
2216
2217 expected_data = [
2218 pa.array(range(5), type=pa.int32()),
2219 pa.array([-10, -5, 0, 5, 10], type=pa.int16()),
2220 pa.array([1, 2, 3, 4, 5], type=pa.int64()),
2221 pa.array(['ab', 'bc', 'cd', 'de', 'ef'], type=pa.string())
2222 ]
2223 expected_table = cls.from_arrays(expected_data, names=tuple('abcd'))
2224
2225 target_schema = pa.schema([
2226 pa.field('a', pa.int32()),
2227 pa.field('b', pa.int16()),
2228 pa.field('c', pa.int64()),
2229 pa.field('d', pa.string())
2230 ])
2231 casted_table = table.cast(target_schema)
2232
2233 assert casted_table.equals(expected_table)
2234
2235
2236@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 6

equalsMethod · 0.80
arrayMethod · 0.45
stringMethod · 0.45
schemaMethod · 0.45
fieldMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected