(self)
| 4035 | assert_(isinstance(t, MyArray)) |
| 4036 | |
| 4037 | def test_put(self): |
| 4038 | icodes = np.typecodes['AllInteger'] |
| 4039 | fcodes = np.typecodes['AllFloat'] |
| 4040 | for dt in icodes + fcodes + 'O': |
| 4041 | tgt = np.array([0, 1, 0, 3, 0, 5], dtype=dt) |
| 4042 | |
| 4043 | # test 1-d |
| 4044 | a = np.zeros(6, dtype=dt) |
| 4045 | a.put([1, 3, 5], [1, 3, 5]) |
| 4046 | assert_equal(a, tgt) |
| 4047 | |
| 4048 | # test 2-d |
| 4049 | a = np.zeros((2, 3), dtype=dt) |
| 4050 | a.put([1, 3, 5], [1, 3, 5]) |
| 4051 | assert_equal(a, tgt.reshape(2, 3)) |
| 4052 | |
| 4053 | for dt in '?': |
| 4054 | tgt = np.array([False, True, False, True, False, True], dtype=dt) |
| 4055 | |
| 4056 | # test 1-d |
| 4057 | a = np.zeros(6, dtype=dt) |
| 4058 | a.put([1, 3, 5], [True] * 3) |
| 4059 | assert_equal(a, tgt) |
| 4060 | |
| 4061 | # test 2-d |
| 4062 | a = np.zeros((2, 3), dtype=dt) |
| 4063 | a.put([1, 3, 5], [True] * 3) |
| 4064 | assert_equal(a, tgt.reshape(2, 3)) |
| 4065 | |
| 4066 | # check must be writeable |
| 4067 | a = np.zeros(6) |
| 4068 | a.flags.writeable = False |
| 4069 | assert_raises(ValueError, a.put, [1, 3, 5], [1, 3, 5]) |
| 4070 | |
| 4071 | # when calling np.put, make sure a |
| 4072 | # TypeError is raised if the object |
| 4073 | # isn't an ndarray |
| 4074 | bad_array = [1, 2, 3] |
| 4075 | assert_raises(TypeError, np.put, bad_array, [0, 2], 5) |
| 4076 | |
| 4077 | # when calling np.put, make sure an |
| 4078 | # IndexError is raised if the |
| 4079 | # array is empty |
| 4080 | empty_array = np.asarray([]) |
| 4081 | with pytest.raises(IndexError, |
| 4082 | match="cannot replace elements of an empty array"): |
| 4083 | np.put(empty_array, 1, 1, mode="wrap") |
| 4084 | with pytest.raises(IndexError, |
| 4085 | match="cannot replace elements of an empty array"): |
| 4086 | np.put(empty_array, 1, 1, mode="clip") |
| 4087 | |
| 4088 | def test_ravel(self): |
| 4089 | a = np.array([[0, 1], [2, 3]]) |
nothing calls this directly
no test coverage detected