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

Function test_tensor_attrs

python/pyarrow/tests/test_tensor.py:46–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44
45
46def test_tensor_attrs():
47 data = np.random.randn(10, 4)
48
49 tensor = pa.Tensor.from_numpy(data)
50
51 assert tensor.ndim == 2
52 assert tensor.dim_names == []
53 assert tensor.size == 40
54 assert tensor.shape == data.shape
55 assert tensor.strides == data.strides
56
57 assert tensor.is_contiguous
58 assert tensor.is_mutable
59
60 # not writeable
61 data2 = data.copy()
62 data2.flags.writeable = False
63 tensor = pa.Tensor.from_numpy(data2)
64 assert not tensor.is_mutable
65
66 # With dim_names
67 tensor = pa.Tensor.from_numpy(data, dim_names=('x', 'y'))
68 assert tensor.ndim == 2
69 assert tensor.dim_names == ['x', 'y']
70 assert tensor.dim_name(0) == 'x'
71 assert tensor.dim_name(1) == 'y'
72
73 wr = weakref.ref(tensor)
74 assert wr() is not None
75 del tensor
76 assert wr() is None
77
78
79def test_tensor_base_object():

Callers

nothing calls this directly

Calls 1

copyMethod · 0.80

Tested by

no test coverage detected