コード例 #1
0
 def test_clean_part_list_list_list_float(self):
     """ Test a float in a list of a list of a list."""
     num = [[[1.0]]]
     num_ = _clean_part(num)
     assert isinstance(num_, list)
     assert np.all([isinstance(part, list) for part in num_])
     np.testing.assert_array_equal(num_[0][0], array([1.0], dtype=float))
コード例 #2
0
 def test_clean_part_list_list_list_float(self):
     """ Test a float in a list of a list of a list."""
     num = [[[1.0]]]
     num_ = _clean_part(num)
     assert isinstance(num_, list)
     assert np.all([isinstance(part, list) for part in num_])
     np.testing.assert_array_equal(num_[0][0], array([1.0], dtype=float))
コード例 #3
0
    def test_clean_part_tuple_scalar(self):
        """Test single scalar value in tuple."""
        num = (1)
        num_ = _clean_part(num)

        assert isinstance(num_, list)
        assert np.all([isinstance(part, list) for part in num_])
        np.testing.assert_array_equal(num_[0][0], array([1.0], dtype=float))
コード例 #4
0
    def test_clean_part_np_array(self):
        """Test multiple values in numpy array."""
        num = np.array([1, 2])
        num_ = _clean_part(num)

        assert isinstance(num_, list)
        assert np.all([isinstance(part, list) for part in num_])
        np.testing.assert_array_equal(num_[0][0], array([1.0, 2.0], dtype=float))
コード例 #5
0
    def test_clean_part_tuple_scalar(self):
        """Test single scalar value in tuple."""
        num = (1)
        num_ = _clean_part(num)

        assert isinstance(num_, list)
        assert np.all([isinstance(part, list) for part in num_])
        np.testing.assert_array_equal(num_[0][0], array([1.0], dtype=float))
コード例 #6
0
 def test_clean_part_tuple_all_types2(self):
     """Test tuple of a single value for all data types."""
     for dtype in [int, int8, int16, int32, int64, float, float16, float32, float64, float128]:
         num = (dtype(1), dtype(2))
         num_ = _clean_part(num)
         assert isinstance(num_, list)
         assert np.all([isinstance(part, list) for part in num_])
         np.testing.assert_array_equal(num_[0][0], array([1, 2], dtype=float))
コード例 #7
0
 def test_clean_part_list_all_types2(self):
     """List of list of numbers of all data types."""
     for dtype in [int, int8, int16, int32, int64, float, float16, float32, float64, float128]:
         num = [dtype(1), dtype(2)]
         num_ = _clean_part(num)
         assert isinstance(num_, list)
         assert np.all([isinstance(part, list) for part in num_])
         np.testing.assert_array_equal(num_[0][0], array([1.0, 2.0], dtype=float))
コード例 #8
0
    def test_clean_part_all_scalar_types(self):
        """Test single scalar value for all valid data types."""
        for dtype in [int, int8, int16, int32, int64, float, float16, float32, float64, float128]:
            num = dtype(1)
            num_ = _clean_part(num)

            assert isinstance(num_, list)
            assert np.all([isinstance(part, list) for part in num_])
            np.testing.assert_array_equal(num_[0][0], array([1.0], dtype=float))
コード例 #9
0
    def test_clean_part_np_array(self):
        """Test multiple values in numpy array."""
        num = np.array([1, 2])
        num_ = _clean_part(num)

        assert isinstance(num_, list)
        assert np.all([isinstance(part, list) for part in num_])
        np.testing.assert_array_equal(num_[0][0], array([1.0, 2.0],
                                                        dtype=float))
コード例 #10
0
    def test_clean_part_list_list_list_ints(self):
        """Test 2 lists of ints in a list in a list."""
        num = [[[1, 1], [2, 2]]]
        num_ = _clean_part(num)

        assert isinstance(num_, list)
        assert np.all([isinstance(part, list) for part in num_])
        np.testing.assert_array_equal(num_[0][0], array([1.0, 1.0], dtype=float))
        np.testing.assert_array_equal(num_[0][1], array([2.0, 2.0], dtype=float))
コード例 #11
0
    def test_clean_part_all_np_array_types(self):
        """Test scalar value in numpy array of ndim=0 for all data types."""
        for dtype in [int, int8, int16, int32, int64, float, float16, float32, float64, float128]:
            num = np.array(1, dtype=dtype)
            num_ = _clean_part(num)

            assert isinstance(num_, list)
            assert np.all([isinstance(part, list) for part in num_])
            np.testing.assert_array_equal(num_[0][0], array([1.0], dtype=float))
コード例 #12
0
    def test_clean_part_list_tuple_array(self):
        """List of tuple of numpy array for all valid types."""
        for dtype in int, int8, int16, int32, int64, float, float16, float32, float64, float128:
            num = [(array([1, 1], dtype=dtype), array([2, 2], dtype=dtype))]
            num_ = _clean_part(num)

            assert isinstance(num_, list)
            assert np.all([isinstance(part, list) for part in num_])
            np.testing.assert_array_equal(num_[0][0], array([1.0, 1.0], dtype=float))
            np.testing.assert_array_equal(num_[0][1], array([2.0, 2.0], dtype=float))
コード例 #13
0
    def test_clean_part_list_list_list_ints(self):
        """Test 2 lists of ints in a list in a list."""
        num = [[[1, 1], [2, 2]]]
        num_ = _clean_part(num)

        assert isinstance(num_, list)
        assert np.all([isinstance(part, list) for part in num_])
        np.testing.assert_array_equal(num_[0][0], array([1.0, 1.0],
                                                        dtype=float))
        np.testing.assert_array_equal(num_[0][1], array([2.0, 2.0],
                                                        dtype=float))
コード例 #14
0
 def test_clean_part_tuple_all_types2(self):
     """Test tuple of a single value for all data types."""
     for dtype in [
             int, int8, int16, int32, int64, float, float16, float32,
             float64, longdouble
     ]:
         num = (dtype(1), dtype(2))
         num_ = _clean_part(num)
         assert isinstance(num_, list)
         assert np.all([isinstance(part, list) for part in num_])
         np.testing.assert_array_equal(num_[0][0], array([1, 2],
                                                         dtype=float))
コード例 #15
0
 def test_clean_part_list_all_types2(self):
     """List of list of numbers of all data types."""
     for dtype in [
             int, int8, int16, int32, int64, float, float16, float32,
             float64, longdouble
     ]:
         num = [dtype(1), dtype(2)]
         num_ = _clean_part(num)
         assert isinstance(num_, list)
         assert np.all([isinstance(part, list) for part in num_])
         np.testing.assert_array_equal(num_[0][0],
                                       array([1.0, 2.0], dtype=float))
コード例 #16
0
    def test_clean_part_list_tuple_array(self):
        """List of tuple of numpy array for all valid types."""
        for dtype in int, int8, int16, int32, int64, float, float16, float32, float64, longdouble:
            num = [(array([1, 1], dtype=dtype), array([2, 2], dtype=dtype))]
            num_ = _clean_part(num)

            assert isinstance(num_, list)
            assert np.all([isinstance(part, list) for part in num_])
            np.testing.assert_array_equal(num_[0][0],
                                          array([1.0, 1.0], dtype=float))
            np.testing.assert_array_equal(num_[0][1],
                                          array([2.0, 2.0], dtype=float))
コード例 #17
0
def test_clean_part(num, fun, dtype):
    """Test clean part for various inputs"""
    numa = fun(dtype, num)
    num_ = _clean_part(numa)
    ref_ = np.array(num, dtype=float, ndmin=3)

    assert isinstance(num_, list)
    assert np.all([isinstance(part, list) for part in num_])
    for i, numi in enumerate(num_):
        assert len(numi) == ref_.shape[1]
        for j, numj in enumerate(numi):
            np.testing.assert_array_equal(numj, ref_[i, j, ...])
コード例 #18
0
 def test_clean_part_list_all_types(self):
     """Test list of a single value for all data types."""
     for dtype in [
             int, int8, int16, int32, int64, float, float16, float32,
             float64, float128
     ]:
         num = [dtype(1)]
         num_ = _clean_part(num)
         assert isinstance(num_, list)
         assert np.all([isinstance(part, list) for part in num_])
         np.testing.assert_array_equal(num_[0][0], array([1.0],
                                                         dtype=float))
コード例 #19
0
    def test_clean_part_all_np_array_types2(self):
        """Test numpy array for all types."""
        for dtype in [
                int, int8, int16, int32, int64, float, float16, float32,
                float64, float128
        ]:
            num = np.array([1, 2], dtype=dtype)
            num_ = _clean_part(num)

            assert isinstance(num_, list)
            assert np.all([isinstance(part, list) for part in num_])
            np.testing.assert_array_equal(num_[0][0],
                                          array([1.0, 2.0], dtype=float))
コード例 #20
0
    def test_clean_part_all_np_array_types(self):
        """Test scalar value in numpy array of ndim=0 for all data types."""
        for dtype in [
                int, int8, int16, int32, int64, float, float16, float32,
                float64, longdouble
        ]:
            num = np.array(1, dtype=dtype)
            num_ = _clean_part(num)

            assert isinstance(num_, list)
            assert np.all([isinstance(part, list) for part in num_])
            np.testing.assert_array_equal(num_[0][0], array([1.0],
                                                            dtype=float))
コード例 #21
0
    def test_clean_part_tuple_tuples_arrays(self):
        """Tuple of tuples of numpy arrays for all valid types."""
        for dtype in int, int8, int16, int32, int64, float, float16, float32, float64, float128:
            num = ((array([1, 1], dtype=dtype), array([2, 2], dtype=dtype)),
                   (array([3, 4], dtype=dtype), array([4, 4], dtype=dtype)))
            num_ = _clean_part(num)

            assert isinstance(num_, list)
            assert np.all([isinstance(part, list) for part in num_])
            np.testing.assert_array_equal(num_[0][0],
                                          array([1.0, 1.0], dtype=float))
            np.testing.assert_array_equal(num_[0][1],
                                          array([2.0, 2.0], dtype=float))
コード例 #22
0
    def test_clean_part_all_scalar_types(self):
        """Test single scalar value for all valid data types."""
        for dtype in [
                int, int8, int16, int32, int64, float, float16, float32,
                float64, longdouble
        ]:
            num = dtype(1)
            num_ = _clean_part(num)

            assert isinstance(num_, list)
            assert np.all([isinstance(part, list) for part in num_])
            np.testing.assert_array_equal(num_[0][0], array([1.0],
                                                            dtype=float))
コード例 #23
0
    def test_clean_part_list_list_arrays(self):
        """List of list of numpy arrays for all valid types."""
        for dtype in int, int8, int16, int32, int64, float, float16, float32, float64, float128:
            num = [[array([1, 1], dtype=dtype), array([2, 2], dtype=dtype)],
                   [array([3, 3], dtype=dtype), array([4, 4], dtype=dtype)]]
            num_ = _clean_part(num)

            assert len(num_) == 2
            assert np.all([isinstance(part, list) for part in num_])
            assert np.all([len(part) == 2 for part in num_])
            np.testing.assert_array_equal(num_[0][0], array([1.0, 1.0], dtype=float))
            np.testing.assert_array_equal(num_[0][1], array([2.0, 2.0], dtype=float))
            np.testing.assert_array_equal(num_[1][0], array([3.0, 3.0], dtype=float))
            np.testing.assert_array_equal(num_[1][1], array([4.0, 4.0], dtype=float))
コード例 #24
0
    def test_clean_part_list_list_arrays(self):
        """List of list of numpy arrays for all valid types."""
        for dtype in int, int8, int16, int32, int64, float, float16, float32, float64, longdouble:
            num = [[array([1, 1], dtype=dtype),
                    array([2, 2], dtype=dtype)],
                   [array([3, 3], dtype=dtype),
                    array([4, 4], dtype=dtype)]]
            num_ = _clean_part(num)

            assert len(num_) == 2
            assert np.all([isinstance(part, list) for part in num_])
            assert np.all([len(part) == 2 for part in num_])
            np.testing.assert_array_equal(num_[0][0],
                                          array([1.0, 1.0], dtype=float))
            np.testing.assert_array_equal(num_[0][1],
                                          array([2.0, 2.0], dtype=float))
            np.testing.assert_array_equal(num_[1][0],
                                          array([3.0, 3.0], dtype=float))
            np.testing.assert_array_equal(num_[1][1],
                                          array([4.0, 4.0], dtype=float))
コード例 #25
0
def test_clean_part_bad_input(badinput):
    """Give the part cleaner invalid input type."""
    with pytest.raises(TypeError):
        _clean_part(badinput)