def test_create_series(self):
     x = np.array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]] * 100)
     a = TensorArray(x)
     s1 = pd.Series(a)
     s2 = pd.Series(a, dtype=TensorDtype())
     s3 = pd.Series(a, dtype=TensorDtype(), copy=True)
     self.assertEqual(len(x), len(s1))
     npt.assert_array_equal(x, s1.to_numpy())
     pdt.assert_series_equal(s1, s2)
     pdt.assert_series_equal(s1, s3)
 def test_arith_series_with_array(self, data, all_arithmetic_operators):
     """ Override because creates Series from list of TensorElements as dtype=object."""
     # ndarray & other series
     op_name = all_arithmetic_operators
     s = pd.Series(data)
     self.check_opname(
         s, op_name, pd.Series([s.iloc[0]] * len(s), dtype=TensorDtype()), exc=self.series_array_exc
     )
    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()))
 def test_compare_array(self, data, all_compare_operators):
     """ Override to change scalar value to something usable."""
     op_name = all_compare_operators
     s = pd.Series(data[1:])
     other = pd.Series([data[0]] * len(s), dtype=TensorDtype())
     self._compare_other(s, data, op_name, other)
def dtype():
    return TensorDtype()