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

Function test_table_unsafe_casting

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

Source from the content-addressed store, hash-verified

2302 ]
2303)
2304def test_table_unsafe_casting(cls):
2305 data = [
2306 pa.array(range(5), type=pa.int64()),
2307 pa.array([-10, -5, 0, 5, 10], type=pa.int32()),
2308 pa.array([1.1, 2.2, 3.3, 4.4, 5.5], type=pa.float64()),
2309 pa.array(['ab', 'bc', 'cd', 'de', 'ef'], type=pa.string())
2310 ]
2311 table = cls.from_arrays(data, names=tuple('abcd'))
2312
2313 expected_data = [
2314 pa.array(range(5), type=pa.int32()),
2315 pa.array([-10, -5, 0, 5, 10], type=pa.int16()),
2316 pa.array([1, 2, 3, 4, 5], type=pa.int64()),
2317 pa.array(['ab', 'bc', 'cd', 'de', 'ef'], type=pa.string())
2318 ]
2319 expected_table = cls.from_arrays(expected_data, names=tuple('abcd'))
2320
2321 target_schema = pa.schema([
2322 pa.field('a', pa.int32()),
2323 pa.field('b', pa.int16()),
2324 pa.field('c', pa.int64()),
2325 pa.field('d', pa.string())
2326 ])
2327
2328 with pytest.raises(pa.ArrowInvalid, match='truncated'):
2329 table.cast(target_schema)
2330
2331 casted_table = table.cast(target_schema, safe=False)
2332 assert casted_table.equals(expected_table)
2333
2334
2335@pytest.mark.numpy

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