Exemple #1
0
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
Exemple #2
0
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)
Exemple #3
0
 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
Exemple #4
0
def test_as_test_asarraylike_dummy():
    dum = DummyArrayLike()
    result = utilities.asarraylike(dum)
    assert result is dum