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

Function test_pyarrow_roundtrip

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

Source from the content-addressed store, hash-verified

347@pytest.mark.parametrize("tz", ['America/New_York', '+07:30', '-04:30'])
348@pytest.mark.parametrize("offset, length", [(0, 3), (0, 2), (1, 2), (2, 1)])
349def test_pyarrow_roundtrip(uint, int, float, np_float_str,
350 unit, tz, offset, length):
351
352 from datetime import datetime as dt
353 arr = [1, 2, None]
354 dt_arr = [dt(2007, 7, 13), None, dt(2007, 7, 15)]
355
356 table = pa.table(
357 {
358 "a": pa.array(arr, type=uint),
359 "b": pa.array(arr, type=int),
360 "c": pa.array(np.array(arr, dtype=np.dtype(np_float_str)),
361 type=float, from_pandas=True),
362 "d": [True, False, True],
363 "e": [True, False, None],
364 "f": ["a", None, "c"],
365 "g": pa.array(dt_arr, type=pa.timestamp(unit, tz=tz))
366 }
367 )
368 table = table.slice(offset, length)
369 result = _from_dataframe(table.__dataframe__())
370
371 assert table.equals(result)
372
373 table_protocol = table.__dataframe__()
374 result_protocol = result.__dataframe__()
375
376 assert table_protocol.num_columns() == result_protocol.num_columns()
377 assert table_protocol.num_rows() == result_protocol.num_rows()
378 assert table_protocol.num_chunks() == result_protocol.num_chunks()
379 assert table_protocol.column_names() == result_protocol.column_names()
380
381
382@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