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

Function test_numpy_asarray

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

Source from the content-addressed store, hash-verified

3522@pytest.mark.numpy
3523@pytest.mark.parametrize("constructor", [pa.table, pa.record_batch])
3524def test_numpy_asarray(constructor):
3525 table = constructor([[1, 2, 3], [4.0, 5.0, 6.0]], names=["a", "b"])
3526 result = np.asarray(table)
3527 expected = np.array([[1, 4], [2, 5], [3, 6]], dtype="float64")
3528 np.testing.assert_allclose(result, expected)
3529
3530 result = np.asarray(table, dtype="int32")
3531 np.testing.assert_allclose(result, expected)
3532 assert result.dtype == "int32"
3533
3534 # no columns
3535 table2 = table.select([])
3536 result = np.asarray(table2)
3537 expected = np.empty((3, 0))
3538 np.testing.assert_allclose(result, expected)
3539 assert result.dtype == "float64"
3540 result = np.asarray(table2, dtype="int32")
3541 np.testing.assert_allclose(result, expected)
3542 assert result.dtype == "int32"
3543
3544 # no rows
3545 table3 = table.slice(0, 0)
3546 result = np.asarray(table3)
3547 expected = np.empty((0, 2))
3548 np.testing.assert_allclose(result, expected)
3549 assert result.dtype == "float64"
3550 result = np.asarray(table3, dtype="int32")
3551 np.testing.assert_allclose(result, expected)
3552 assert result.dtype == "int32"
3553
3554
3555@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