def test_asarraylike_array(): """ Passing in a list should return a np.ndarray. """ arr = np.array([1, 2, 3, 4]) result = utilities.asarraylike(arr) assert result is arr
def test_asarraylike_list(): """ Passing in a list should return a np.ndarray. """ lst = [1, 2, 3, 4] result = utilities.asarraylike(lst) assert isinstance(result, np.ndarray) assert np.array_equal(result, lst)
def data(self, d): d = asarraylike(d) # Fixme: maybe all this checking should be done when it gets added to the Dataset?? if self.time is not None and len(d) != len(self.time): raise ValueError("Data/time interval mismatch") ## fixme: we should check Depth, too. # if self.grid is not None and self.grid.infer_location(d) is None: # raise ValueError("Data/grid shape mismatch. Data shape is {0}, Grid shape is {1}".format(d.shape, self.grid.node_lon.shape)) if self.grid is not None: # if there is not a grid, we can't check this if self.location is None: # not set, let's try to figure it out self.location = self.grid.infer_location(d) if self.location is None: raise ValueError( "Data/grid shape mismatch: Data shape is {0}, " "Grid shape is {1}".format(d.shape, self.grid.node_lon.shape)) self._data = d
def test_as_test_asarraylike_dummy(): dum = DummyArrayLike() result = utilities.asarraylike(dum) assert result is dum