def test_array_interface(self):
        # Extended version of Pandas TestPandasInterface.test_array_interface

        # Test scalar value
        s = TensorArray(3)
        result = np.array(s)
        self.assertTupleEqual(result.shape, (1,))
        expected = np.stack([np.asarray(i) for i in s])
        npt.assert_array_equal(result, expected)

        # Test scalar list
        s = TensorArray([1, 2, 3])
        result = np.array(s)
        self.assertTupleEqual(result.shape, (3,))
        expected = np.stack([np.asarray(i) for i in s])
        npt.assert_array_equal(result, expected)

        # Test 2d array
        s = TensorArray([[1], [2], [3]])
        result = np.array(s)
        self.assertTupleEqual(result.shape, (3, 1))
        expected = np.array([np.asarray(i) for i in s])
        npt.assert_array_equal(result, expected)

        # Test TensorElement
        x = [1, 2, 3]
        elements = [TensorElement(np.array(i)) for i in x]
        result = np.array([np.asarray(e) for e in elements])
        self.assertTupleEqual(result.shape, (3,))
        expected = np.array(x)
        npt.assert_array_equal(result, expected)
    def test_create_from_scalar(self):
        s = TensorArray(2112)
        self.assertEqual(len(s), 1)
        self.assertTupleEqual(s.numpy_shape, (1,))
        self.assertEqual(s[0], 2112)

        s = TensorArray(np.int64(2112))
        self.assertEqual(len(s), 1)
        self.assertTupleEqual(s.numpy_shape, (1,))
        self.assertEqual(s[0], 2112)

        x = np.array([1, 2112, 3])
        e = TensorElement(x[1])
        s = TensorArray(e)
        self.assertTupleEqual(s.numpy_shape, (1,))
        self.assertEqual(s[0], 2112)
    def test_create_from_scalar_list(self):
        x = [1, 2, 3, 4, 5]
        s = TensorArray(x)
        self.assertTupleEqual(s.numpy_shape, (len(x),))
        expected = np.array(x)
        npt.assert_array_equal(s.to_numpy(), expected)

        # Now with TensorElement values
        e = [TensorElement(np.array(i)) for i in x]
        s = pd.array(e, dtype=TensorDtype())
        npt.assert_array_equal(s.to_numpy(), expected)

        # Now with list of 1d tensors
        x = [np.array([i]) for i in x]
        s = pd.array(x, dtype=TensorDtype())
        self.assertTupleEqual(s.to_numpy().shape, (len(x), 1))
        npt.assert_array_equal(s.to_numpy(), np.array([[e] for e in expected]))

        # Pandas will create list of copies of the tensor element for the given indices
        s = pd.Series(np.nan, index=[0, 1, 2], dtype=TensorDtype())
        self.assertEqual(len(s), 3)
        self.assertTupleEqual(s.to_numpy().shape, (3,))
        result = s.isna()
        self.assertTrue(np.all(result.to_numpy()))