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

Function test_numpy_asarray

python/pyarrow/tests/test_table.py:3585–3613  ·  view source on GitHub ↗
(constructor)

Source from the content-addressed store, hash-verified

3583@pytest.mark.numpy
3584@pytest.mark.parametrize("constructor", [pa.table, pa.record_batch])
3585def test_numpy_asarray(constructor):
3586 table = constructor([[1, 2, 3], [4.0, 5.0, 6.0]], names=["a", "b"])
3587 result = np.asarray(table)
3588 expected = np.array([[1, 4], [2, 5], [3, 6]], dtype="float64")
3589 np.testing.assert_allclose(result, expected)
3590
3591 result = np.asarray(table, dtype="int32")
3592 np.testing.assert_allclose(result, expected)
3593 assert result.dtype == "int32"
3594
3595 # no columns
3596 table2 = table.select([])
3597 result = np.asarray(table2)
3598 expected = np.empty((3, 0))
3599 np.testing.assert_allclose(result, expected)
3600 assert result.dtype == "float64"
3601 result = np.asarray(table2, dtype="int32")
3602 np.testing.assert_allclose(result, expected)
3603 assert result.dtype == "int32"
3604
3605 # no rows
3606 table3 = table.slice(0, 0)
3607 result = np.asarray(table3)
3608 expected = np.empty((0, 2))
3609 np.testing.assert_allclose(result, expected)
3610 assert result.dtype == "float64"
3611 result = np.asarray(table3, dtype="int32")
3612 np.testing.assert_allclose(result, expected)
3613 assert result.dtype == "int32"
3614
3615
3616@pytest.mark.numpy

Callers

nothing calls this directly

Calls 4

arrayMethod · 0.45
selectMethod · 0.45
emptyMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected