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

Function test_pyarrow_roundtrip

python/pyarrow/tests/interchange/test_conversion.py:392–422  ·  view source on GitHub ↗
(uint, int, float, np_float_str,
                           unit, tz, offset, length)

Source from the content-addressed store, hash-verified

390@pytest.mark.parametrize("tz", ['America/New_York', '+07:30', '-04:30'])
391@pytest.mark.parametrize("offset, length", [(0, 3), (0, 2), (1, 2), (2, 1)])
392def test_pyarrow_roundtrip(uint, int, float, np_float_str,
393 unit, tz, offset, length):
394
395 from datetime import datetime as dt
396 arr = [1, 2, None]
397 dt_arr = [dt(2007, 7, 13), None, dt(2007, 7, 15)]
398
399 table = pa.table(
400 {
401 "a": pa.array(arr, type=uint),
402 "b": pa.array(arr, type=int),
403 "c": pa.array(np.array(arr, dtype=np.dtype(np_float_str)),
404 type=float, from_pandas=True),
405 "d": [True, False, True],
406 "e": [True, False, None],
407 "f": ["a", None, "c"],
408 "g": pa.array(dt_arr, type=pa.timestamp(unit, tz=tz))
409 }
410 )
411 table = table.slice(offset, length)
412 result = _from_dataframe(table.__dataframe__())
413
414 assert table.equals(result)
415
416 table_protocol = table.__dataframe__()
417 result_protocol = result.__dataframe__()
418
419 assert table_protocol.num_columns() == result_protocol.num_columns()
420 assert table_protocol.num_rows() == result_protocol.num_rows()
421 assert table_protocol.num_chunks() == result_protocol.num_chunks()
422 assert table_protocol.column_names() == result_protocol.column_names()
423
424
425@pytest.mark.parametrize("offset, length", [(0, 10), (0, 2), (7, 3), (2, 1)])

Callers

nothing calls this directly

Calls 10

_from_dataframeFunction · 0.90
dtypeMethod · 0.80
__dataframe__Method · 0.80
equalsMethod · 0.80
arrayMethod · 0.45
sliceMethod · 0.45
num_columnsMethod · 0.45
num_rowsMethod · 0.45
num_chunksMethod · 0.45
column_namesMethod · 0.45

Tested by

no test coverage detected