| 44 | |
| 45 | |
| 46 | def 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 | |
| 79 | def test_tensor_base_object(): |