def test_cast_scalar_to_array(self): arr = cast_scalar_to_array((3, 2), 1, dtype=np.int64) exp = np.ones((3, 2), dtype=np.int64) tm.assert_numpy_array_equal(arr, exp) arr = cast_scalar_to_array((3, 2), 1.1) exp = np.empty((3, 2), dtype=np.float64) exp.fill(1.1) tm.assert_numpy_array_equal(arr, exp) arr = cast_scalar_to_array((2, 3), Timestamp('2011-01-01')) exp = np.empty((2, 3), dtype='datetime64[ns]') exp.fill(np.datetime64('2011-01-01')) tm.assert_numpy_array_equal(arr, exp) # pandas dtype is stored as object dtype obj = Timestamp('2011-01-01', tz='US/Eastern') arr = cast_scalar_to_array((2, 3), obj) exp = np.empty((2, 3), dtype=np.object) exp.fill(obj) tm.assert_numpy_array_equal(arr, exp) obj = Period('2011-01-01', freq='D') arr = cast_scalar_to_array((2, 3), obj) exp = np.empty((2, 3), dtype=np.object) exp.fill(obj) tm.assert_numpy_array_equal(arr, exp)
def test_cast_scalar_to_array(self): arr = cast_scalar_to_array((3, 2), 1, dtype=np.int64) exp = np.ones((3, 2), dtype=np.int64) tm.assert_numpy_array_equal(arr, exp) arr = cast_scalar_to_array((3, 2), 1.1) exp = np.empty((3, 2), dtype=np.float64) exp.fill(1.1) tm.assert_numpy_array_equal(arr, exp) arr = cast_scalar_to_array((2, 3), Timestamp('2011-01-01')) exp = np.empty((2, 3), dtype='datetime64[ns]') exp.fill(np.datetime64('2011-01-01')) tm.assert_numpy_array_equal(arr, exp) # pandas dtype is stored as object dtype obj = Timestamp('2011-01-01', tz='US/Eastern') arr = cast_scalar_to_array((2, 3), obj) exp = np.empty((2, 3), dtype=np.object) exp.fill(obj) tm.assert_numpy_array_equal(arr, exp) obj = Period('2011-01-01', freq='D') arr = cast_scalar_to_array((2, 3), obj) exp = np.empty((2, 3), dtype=np.object) exp.fill(obj) tm.assert_numpy_array_equal(arr, exp)
def test_cast_scalar_to_array(obj, dtype): shape = (3, 2) exp = np.empty(shape, dtype=dtype) exp.fill(obj) arr = cast_scalar_to_array(shape, obj, dtype=dtype) tm.assert_numpy_array_equal(arr, exp)
def test_cast_scalar_to_array(obj, dtype): shape = (3, 2) exp = np.empty(shape, dtype=dtype) exp.fill(obj) arr = cast_scalar_to_array(shape, obj, dtype=dtype) tm.assert_numpy_array_equal(arr, exp)