def test_empty(self): a = create_data_array(self.coords, data=None) assert isinstance(a, UnitsDataArray) assert a.shape == self.coords.shape assert a.dtype == float a = create_data_array(self.coords, data=None, dtype=bool) assert isinstance(a, UnitsDataArray) assert a.shape == self.coords.shape assert a.dtype == bool
def test_array(self): data = np.random.random(self.coords.shape) a = create_data_array(self.coords, data=data) assert isinstance(a, UnitsDataArray) assert a.dtype == float np.testing.assert_equal(a.data, data) data = np.round(10 * np.random.random(self.coords.shape)) a = create_data_array(self.coords, data=data, dtype=int) assert isinstance(a, UnitsDataArray) assert a.dtype == int np.testing.assert_equal(a.data, data.astype(int))
def test_full(self): a = create_data_array(self.coords, data=10) assert isinstance(a, UnitsDataArray) assert a.shape == self.coords.shape assert a.dtype == float assert np.all(a == 10) a = create_data_array(self.coords, data=10, dtype=int) assert isinstance(a, UnitsDataArray) assert a.shape == self.coords.shape assert a.dtype == int assert np.all(a == 10)
def test_ones(self): a = create_data_array(self.coords, data=1) assert isinstance(a, UnitsDataArray) assert a.shape == self.coords.shape assert a.dtype == float assert np.all(a == 1.0) a = create_data_array(self.coords, data=1, dtype=bool) assert isinstance(a, UnitsDataArray) assert a.shape == self.coords.shape assert a.dtype == bool assert np.all(a)
def create_output_array(self, coords, data=np.nan, **kwargs): """ Initialize an output data array Parameters ---------- coords : podpac.Coordinates {arr_coords} data : None, number, or array-like (optional) {arr_init_type} **kwargs {arr_kwargs} Returns ------- {arr_return} """ attrs = {'layer_style': self.style, 'units': self.units} return create_data_array(coords, data=data, dtype=self.dtype, attrs=attrs, **kwargs)
def test_invalid_coords(self): with pytest.raises(TypeError): create_data_array((3, 4))
def test_default(self): a = create_data_array(self.coords) assert isinstance(a, UnitsDataArray) assert a.shape == self.coords.shape assert np.all(np.isnan(a))