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

Function test_table_safe_casting

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

Source from the content-addressed store, hash-verified

2267 ]
2268)
2269def test_table_safe_casting(cls):
2270 data = [
2271 pa.array(range(5), type=pa.int64()),
2272 pa.array([-10, -5, 0, 5, 10], type=pa.int32()),
2273 pa.array([1.0, 2.0, 3.0, 4.0, 5.0], type=pa.float64()),
2274 pa.array(['ab', 'bc', 'cd', 'de', 'ef'], type=pa.string())
2275 ]
2276 table = cls.from_arrays(data, names=tuple('abcd'))
2277
2278 expected_data = [
2279 pa.array(range(5), type=pa.int32()),
2280 pa.array([-10, -5, 0, 5, 10], type=pa.int16()),
2281 pa.array([1, 2, 3, 4, 5], type=pa.int64()),
2282 pa.array(['ab', 'bc', 'cd', 'de', 'ef'], type=pa.string())
2283 ]
2284 expected_table = cls.from_arrays(expected_data, names=tuple('abcd'))
2285
2286 target_schema = pa.schema([
2287 pa.field('a', pa.int32()),
2288 pa.field('b', pa.int16()),
2289 pa.field('c', pa.int64()),
2290 pa.field('d', pa.string())
2291 ])
2292 casted_table = table.cast(target_schema)
2293
2294 assert casted_table.equals(expected_table)
2295
2296
2297@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