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

Function test_numpy_asarray

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

Source from the content-addressed store, hash-verified

3411@pytest.mark.numpy
3412@pytest.mark.parametrize("constructor", [pa.table, pa.record_batch])
3413def test_numpy_asarray(constructor):
3414 table = constructor([[1, 2, 3], [4.0, 5.0, 6.0]], names=["a", "b"])
3415 result = np.asarray(table)
3416 expected = np.array([[1, 4], [2, 5], [3, 6]], dtype="float64")
3417 np.testing.assert_allclose(result, expected)
3418
3419 result = np.asarray(table, dtype="int32")
3420 np.testing.assert_allclose(result, expected)
3421 assert result.dtype == "int32"
3422
3423 # no columns
3424 table2 = table.select([])
3425 result = np.asarray(table2)
3426 expected = np.empty((3, 0))
3427 np.testing.assert_allclose(result, expected)
3428 assert result.dtype == "float64"
3429 result = np.asarray(table2, dtype="int32")
3430 np.testing.assert_allclose(result, expected)
3431 assert result.dtype == "int32"
3432
3433 # no rows
3434 table3 = table.slice(0, 0)
3435 result = np.asarray(table3)
3436 expected = np.empty((0, 2))
3437 np.testing.assert_allclose(result, expected)
3438 assert result.dtype == "float64"
3439 result = np.asarray(table3, dtype="int32")
3440 np.testing.assert_allclose(result, expected)
3441 assert result.dtype == "int32"
3442
3443
3444@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