@@ -164,14 +164,25 @@ def array_abbreviation():
164164 """
165165 Numpy abbreviates arrays, check that it works.
166166
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+
172180 >>> import numpy as np
173181 >>> 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)
175186
176187 >>> np.diag(np.arange(33)) / 30
177188 array([[0., 0., 0., ..., 0., 0.,0.],
@@ -180,53 +191,17 @@ def array_abbreviation():
180191 ...,
181192 [0., 0., 0., ..., 1., 0., 0.],
182193 [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) )
184195
185196
186- >>> np.diag(np.arange(1, 1001, dtype=float ))
197+ >>> np.diag(np.arange(1, 1001, dtype=np.uint16 ))
187198 array([[1, 0, 0, ..., 0, 0, 0],
188199 [0, 2, 0, ..., 0, 0, 0],
189200 [0, 0, 3, ..., 0, 0, 0],
190201 ...,
191202 [0, 0, 0, ..., 998, 0, 0],
192203 [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)
230205 """
231206
232207
0 commit comments