MCPcopy Index your code
hub / github.com/numpy/numpy / test_attributes

Method test_attributes

numpy/_core/tests/test_regression.py:1117–1185  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1115 pass
1116
1117 def test_attributes(self):
1118 # Ticket #791
1119 class TestArray(np.ndarray):
1120 def __new__(cls, data, info):
1121 result = np.array(data)
1122 result = result.view(cls)
1123 result.info = info
1124 return result
1125
1126 def __array_finalize__(self, obj):
1127 self.info = getattr(obj, 'info', '')
1128
1129 dat = TestArray([[1, 2, 3, 4], [5, 6, 7, 8]], 'jubba')
1130 assert_(dat.info == 'jubba')
1131 dat.resize((4, 2))
1132 assert_(dat.info == 'jubba')
1133 dat.sort()
1134 assert_(dat.info == 'jubba')
1135 dat.fill(2)
1136 assert_(dat.info == 'jubba')
1137 dat.put([2, 3, 4], [6, 3, 4])
1138 assert_(dat.info == 'jubba')
1139 dat.setfield(4, np.int32, 0)
1140 assert_(dat.info == 'jubba')
1141 dat.setflags()
1142 assert_(dat.info == 'jubba')
1143 assert_(dat.all(1).info == 'jubba')
1144 assert_(dat.any(1).info == 'jubba')
1145 assert_(dat.argmax(1).info == 'jubba')
1146 assert_(dat.argmin(1).info == 'jubba')
1147 assert_(dat.argsort(1).info == 'jubba')
1148 assert_(dat.astype(TestArray).info == 'jubba')
1149 assert_(dat.byteswap().info == 'jubba')
1150 assert_(dat.clip(2, 7).info == 'jubba')
1151 assert_(dat.compress([0, 1, 1]).info == 'jubba')
1152 assert_(dat.conj().info == 'jubba')
1153 assert_(dat.conjugate().info == 'jubba')
1154 assert_(dat.copy().info == 'jubba')
1155 dat2 = TestArray([2, 3, 1, 0], 'jubba')
1156 choices = [[0, 1, 2, 3], [10, 11, 12, 13],
1157 [20, 21, 22, 23], [30, 31, 32, 33]]
1158 assert_(dat2.choose(choices).info == 'jubba')
1159 assert_(dat.cumprod(1).info == 'jubba')
1160 assert_(dat.cumsum(1).info == 'jubba')
1161 assert_(dat.diagonal().info == 'jubba')
1162 assert_(dat.flatten().info == 'jubba')
1163 assert_(dat.getfield(np.int32, 0).info == 'jubba')
1164 assert_(dat.imag.info == 'jubba')
1165 assert_(dat.max(1).info == 'jubba')
1166 assert_(dat.mean(1).info == 'jubba')
1167 assert_(dat.min(1).info == 'jubba')
1168 assert_(dat.prod(1).info == 'jubba')
1169 assert_(dat.ravel().info == 'jubba')
1170 assert_(dat.real.info == 'jubba')
1171 assert_(dat.repeat(2).info == 'jubba')
1172 assert_(dat.reshape((2, 4)).info == 'jubba')
1173 assert_(dat.round().info == 'jubba')
1174 assert_(dat.squeeze().info == 'jubba')

Callers

nothing calls this directly

Calls 15

assert_Function · 0.90
resizeMethod · 0.80
putMethod · 0.80
astypeMethod · 0.80
byteswapMethod · 0.80
clipMethod · 0.80
compressMethod · 0.80
conjugateMethod · 0.80
cumprodMethod · 0.80
cumsumMethod · 0.80
flattenMethod · 0.80
reshapeMethod · 0.80

Tested by

no test coverage detected