@@ -164,14 +164,25 @@ def array_abbreviation():
164
164
"""
165
165
Numpy abbreviates arrays, check that it works.
166
166
167
- NB: the implementation might need to change when
168
- numpy finally disallows default-creating ragged arrays.
169
- Currently, `...` gets interpreted as an Ellipsis,
170
- thus the `a_want/a_got` variables in DTChecker are in fact
171
- object arrays.
167
+ XXX: check if ... creates ragged arrays, avoid if so.
168
+
169
+ NumPy 2.2 abbreviations
170
+ =======================
171
+
172
+ NumPy 2.2 adds shape=(...) to abbreviated arrays.
173
+
174
+ This is not a valid argument to `array(...), so it cannot be eval-ed,
175
+ and need to be removed for doctesting.
176
+
177
+ The implementation handles both formats, and checks the shapes if present
178
+ in the actual output. If not present in the output, they are ignored.
179
+
172
180
>>> import numpy as np
173
181
>>> np.arange(10000)
174
- array([0, 1, 2, ..., 9997, 9998, 9999])
182
+ array([0, 1, 2, ..., 9997, 9998, 9999], shape=(10000,))
183
+
184
+ >>> np.arange(10000, dtype=np.uint16)
185
+ array([ 0, 1, 2, ..., 9997, 9998, 9999], shape=(10000,), dtype=uint16)
175
186
176
187
>>> np.diag(np.arange(33)) / 30
177
188
array([[0., 0., 0., ..., 0., 0.,0.],
@@ -180,53 +191,17 @@ def array_abbreviation():
180
191
...,
181
192
[0., 0., 0., ..., 1., 0., 0.],
182
193
[0., 0., 0., ..., 0., 1.03333333, 0.],
183
- [0., 0., 0., ..., 0., 0., 1.06666667]])
194
+ [0., 0., 0., ..., 0., 0., 1.06666667]], shape=(33, 33) )
184
195
185
196
186
- >>> np.diag(np.arange(1, 1001, dtype=float ))
197
+ >>> np.diag(np.arange(1, 1001, dtype=np.uint16 ))
187
198
array([[1, 0, 0, ..., 0, 0, 0],
188
199
[0, 2, 0, ..., 0, 0, 0],
189
200
[0, 0, 3, ..., 0, 0, 0],
190
201
...,
191
202
[0, 0, 0, ..., 998, 0, 0],
192
203
[0, 0, 0, ..., 0, 999, 0],
193
- [0, 0, 0, ..., 0, 0, 1000]])
194
- """
195
-
196
-
197
- def array_abbreviation_2 ():
198
- """ NumPy 2.2 adds shape=(...) to abbreviated arrays.
199
-
200
- So the actual numpy==2.2.0 output below is
201
- # array([ 0, 1, 2, ..., 9997, 9998, 9999], shape=(10000,))
202
-
203
- This is not a valid argument to `array(...), so it cannot be eval-ed,
204
- and need to be removed for doctesting.
205
-
206
- >>> import numpy as np
207
- >>> np.arange(10000)
208
- array([ 0, 1, 2, ..., 9997, 9998, 9999])
209
-
210
- >>> np.arange(10000, dtype=np.uint16)
211
- array([ 0, 1, 2, ..., 9997, 9998, 9999], dtype=np.uint16)
212
-
213
- >>> np.arange(5000).reshape(50, 100)
214
- array([[ 0, 1, 2, ..., 97, 98, 99],
215
- [ 100, 101, 102, ..., 197, 198, 199],
216
- [ 200, 201, 202, ..., 297, 298, 299],
217
- ...,
218
- [4700, 4701, 4702, ..., 4797, 4798, 4799],
219
- [4800, 4801, 4802, ..., 4897, 4898, 4899],
220
- [4900, 4901, 4902, ..., 4997, 4998, 4999]])
221
-
222
- >>> np.arange(5000, dtype=np.uint16).reshape(50, 100)
223
- array([[ 0, 1, 2, ..., 97, 98, 99],
224
- [ 100, 101, 102, ..., 197, 198, 199],
225
- [ 200, 201, 202, ..., 297, 298, 299],
226
- ...,
227
- [4700, 4701, 4702, ..., 4797, 4798, 4799],
228
- [4800, 4801, 4802, ..., 4897, 4898, 4899],
229
- [4900, 4901, 4902, ..., 4997, 4998, 4999]], dtype=uint16)
204
+ [0, 0, 0, ..., 0, 0, 1000]], shape=(1000, 1000), dtype=uint16)
230
205
"""
231
206
232
207
0 commit comments