@@ -286,33 +286,47 @@ def test_array_deepcopy_h(self) -> None:
286
286
a2 = array_deepcopy (a1 , ())
287
287
288
288
#---------------------------------------------------------------------------
289
- def test_array2d_to_array1d_1d_a (self ) -> None :
289
+ def test_array_to_tuple_array_1d_a (self ) -> None :
290
290
a1 = np .arange (10 )
291
291
a2 = array_to_tuple_array (a1 )
292
292
self .assertEqual (a2 .tolist (), [(0 ,), (1 ,), (2 ,), (3 ,), (4 ,), (5 ,), (6 ,), (7 ,), (8 ,), (9 ,)])
293
293
294
- def test_array2d_to_array1d_1d_b (self ) -> None :
294
+ def test_array_to_tuple_array_1d_b (self ) -> None :
295
295
a1 = np .array (['aaa' , 'b' , 'ccc' ])
296
296
a2 = array_to_tuple_array (a1 )
297
297
self .assertEqual (a2 .tolist (), [('aaa' ,), ('b' ,), ('ccc' ,)])
298
298
299
- def test_array2d_to_array1d_1d_c (self ) -> None :
299
+ def test_array_to_tuple_array_1d_c (self ) -> None :
300
300
a1 = np .array ([None , 'b' , 30 ])
301
301
a2 = array_to_tuple_array (a1 )
302
302
self .assertEqual (a2 .tolist (), [(None ,), ('b' ,), (30 ,)])
303
303
304
- def test_array2d_to_array1d_1d_d (self ) -> None :
304
+ def test_array_to_tuple_array_1d_d (self ) -> None :
305
305
a1 = np .array ([('a' , 10 ), ('b' , 30 ), ('c' , 5 )], dtype = object )
306
- a2 = array_to_tuple_array (a1 )
306
+ a2 = array_to_tuple_array (a1 ) # from 2d
307
307
self .assertEqual (a2 .tolist (), [('a' , 10 ), ('b' , 30 ), ('c' , 5 )])
308
+ a3 = array_to_tuple_array (a2 ) # from 1d
309
+ self .assertEqual (a3 .tolist (), [('a' , 10 ), ('b' , 30 ), ('c' , 5 )])
308
310
309
- def test_array2d_to_array1d_1d_e (self ) -> None :
311
+ def test_array_to_tuple_array_1d_e (self ) -> None :
310
312
a1 = np .array ([True , False , True ], dtype = object )
311
313
a2 = array_to_tuple_array (a1 )
312
314
self .assertIs (a2 [0 ][0 ].__class__ , bool )
313
315
self .assertEqual (a2 .tolist (), [(True ,), (False ,), (True ,)])
314
316
315
- def test_array2d_to_array1d_b (self ) -> None :
317
+ def test_array_to_tuple_array_1d_f (self ) -> None :
318
+ a1 = np .array ([None , None , None ], dtype = object )
319
+ a1 [0 ] = 3
320
+ a1 [1 ] = ('a' , 30 )
321
+ a1 [2 ] = (None , True , 90000000 )
322
+
323
+ a2 = array_to_tuple_array (a1 )
324
+ self .assertEqual (a2 .tolist (), [(3 ,), ('a' , 30 ), (None , True , 90000000 )])
325
+
326
+ a3 = array_to_tuple_array (a2 )
327
+ self .assertEqual (a3 .tolist (), [(3 ,), ('a' , 30 ), (None , True , 90000000 )])
328
+
329
+ def test_array_to_tuple_array_b (self ) -> None :
316
330
a1 = np .arange (10 , dtype = np .int64 ).reshape (5 , 2 )
317
331
result = array_to_tuple_array (a1 )
318
332
assert isinstance (result [0 ], tuple )
@@ -322,35 +336,35 @@ def test_array2d_to_array1d_b(self) -> None:
322
336
self .assertEqual (tuple (result ), ((0 , 1 ), (2 , 3 ), (4 , 5 ), (6 , 7 ), (8 , 9 )))
323
337
324
338
325
- def test_array2d_to_array1d_c (self ) -> None :
339
+ def test_array_to_tuple_array_c (self ) -> None :
326
340
a1 = np .array ([["a" , "b" ], ["ccc" , "ddd" ], ["ee" , "ff" ]])
327
341
a2 = array_to_tuple_array (a1 )
328
342
self .assertEqual (a2 .tolist (), [('a' , 'b' ), ('ccc' , 'ddd' ), ('ee' , 'ff' )])
329
343
330
- def test_array2d_to_array1d_d (self ) -> None :
344
+ def test_array_to_tuple_array_d (self ) -> None :
331
345
a1 = np .array ([[3 , 5 ], [10 , 20 ], [7 , 2 ]], dtype = np .uint8 )
332
346
a2 = array_to_tuple_array (a1 )
333
347
self .assertEqual (a2 .tolist (), [(3 , 5 ), (10 , 20 ), (7 , 2 )])
334
348
self .assertIs (type (a2 [0 ][0 ]), np .uint8 )
335
349
336
- def test_array2d_to_array1d_e (self ) -> None :
350
+ def test_array_to_tuple_array_e (self ) -> None :
337
351
a1 = np .arange (20 , dtype = np .int64 ).reshape (4 , 5 )
338
352
result = array_to_tuple_array (a1 )
339
353
self .assertEqual (result .tolist (), [(0 , 1 , 2 , 3 , 4 ), (5 , 6 , 7 , 8 , 9 ), (10 , 11 , 12 , 13 , 14 ), (15 , 16 , 17 , 18 , 19 )])
340
354
341
355
#---------------------------------------------------------------------------
342
- def test_array2d_tuple_iter_a (self ) -> None :
356
+ def test_array_to_tuple_iter_a (self ) -> None :
343
357
a1 = np .arange (20 , dtype = np .int64 ).reshape (4 , 5 )
344
358
result = list (array_to_tuple_iter (a1 ))
345
359
self .assertEqual (len (result ), 4 )
346
360
self .assertEqual (result , [(0 , 1 , 2 , 3 , 4 ), (5 , 6 , 7 , 8 , 9 ), (10 , 11 , 12 , 13 , 14 ), (15 , 16 , 17 , 18 , 19 )])
347
361
348
- def test_array2d_tuple_iter_b (self ) -> None :
362
+ def test_array_to_tuple_iter_b (self ) -> None :
349
363
a1 = np .arange (20 , dtype = np .int64 ).reshape (10 , 2 )
350
364
result = list (array_to_tuple_iter (a1 ))
351
365
self .assertEqual (result , [(0 , 1 ), (2 , 3 ), (4 , 5 ), (6 , 7 ), (8 , 9 ), (10 , 11 ), (12 , 13 ), (14 , 15 ), (16 , 17 ), (18 , 19 )])
352
366
353
- def test_array2d_tuple_iter_c (self ) -> None :
367
+ def test_array_to_tuple_iter_c (self ) -> None :
354
368
a1 = np .array ([['aaa' , 'bb' ], ['c' , 'dd' ], ['ee' , 'fffff' ]])
355
369
it = array_to_tuple_iter (a1 )
356
370
self .assertEqual (it .__length_hint__ (), 3 )
@@ -363,52 +377,62 @@ def test_array2d_tuple_iter_c(self) -> None:
363
377
with self .assertRaises (StopIteration ):
364
378
next (it )
365
379
366
- def test_array2d_tuple_iter_d (self ) -> None :
380
+ def test_array_to_tuple_iter_d (self ) -> None :
367
381
a1 = np .array ([['aaa' , 'bb' ], ['c' , 'dd' ], ['ee' , 'fffff' ]])
368
382
it = array_to_tuple_iter (a1 )
369
383
# __reversed__ not implemented
370
384
with self .assertRaises (TypeError ):
371
385
reversed (it )
372
386
373
- def test_array2d_tuple_iter_e (self ) -> None :
387
+ def test_array_to_tuple_iter_e (self ) -> None :
374
388
a1 = np .array ([[None , 'bb' ], [None , 'dd' ], [3 , None ]])
375
389
it = array_to_tuple_iter (a1 )
376
390
del a1
377
391
self .assertEqual (list (it ), [(None , 'bb' ), (None , 'dd' ), (3 , None )])
378
392
379
- def test_array2d_tuple_iter_f (self ) -> None :
393
+ def test_array_to_tuple_iter_f (self ) -> None :
380
394
a1 = np .array ([[None , 'bb' ], [None , 'dd' ], [3 , None ]])
381
395
it1 = array_to_tuple_iter (a1 )
382
396
del a1
383
397
it2 = iter (it1 )
384
398
self .assertEqual (list (it1 ), [(None , 'bb' ), (None , 'dd' ), (3 , None )])
385
399
self .assertEqual (list (it2 ), []) # expected behavior
386
400
387
- def test_array2d_tuple_iter_g (self ) -> None :
401
+ def test_array_to_tuple_iter_g (self ) -> None :
388
402
a1 = np .array ([[None , 'bb' ], [None , 'dd' ], [3 , None ]])
389
403
it1 = array_to_tuple_iter (a1 )
390
404
it2 = array_to_tuple_iter (a1 )
391
405
del a1
392
406
self .assertEqual (list (it1 ), [(None , 'bb' ), (None , 'dd' ), (3 , None )])
393
407
self .assertEqual (list (it2 ), [(None , 'bb' ), (None , 'dd' ), (3 , None )])
394
408
395
- def test_array2d_tuple_iter_1d_a (self ) -> None :
409
+ def test_array_to_tuple_iter_1d_a (self ) -> None :
396
410
a1 = np .array (['bb' , 'c' , 'aaa' ])
397
411
result = list (array_to_tuple_iter (a1 ))
398
412
self .assertEqual (len (result ), 3 )
399
413
self .assertEqual (result , [('bb' ,), ('c' ,), ('aaa' ,)])
400
414
401
- def test_array2d_tuple_iter_1d_b (self ) -> None :
415
+ def test_array_to_tuple_iter_1d_b (self ) -> None :
402
416
a1 = np .array ([20 , - 1 , 8 ])
403
417
result = list (array_to_tuple_iter (a1 ))
404
418
self .assertEqual (len (result ), 3 )
405
419
self .assertEqual (result , [(20 ,), (- 1 ,), (8 ,)])
406
420
407
- def test_array2d_tuple_iter_1d_c (self ) -> None :
421
+ def test_array_to_tuple_iter_1d_c (self ) -> None :
408
422
a1 = np .array ([('a' , 4 ), ('c' , - 1 ), ('d' , 8 )], dtype = object )
409
- result = list (array_to_tuple_iter (a1 ))
410
- self .assertEqual (len (result ), 3 )
411
- self .assertEqual (result , [('a' , 4 ), ('c' , - 1 ), ('d' , 8 )])
423
+ a2 = list (array_to_tuple_iter (a1 ))
424
+ self .assertEqual (len (a2 ), 3 )
425
+ self .assertEqual (a2 , [('a' , 4 ), ('c' , - 1 ), ('d' , 8 )])
426
+
427
+ def test_array_to_tuple_iter_1d_d (self ) -> None :
428
+ a1 = np .array ([None , None , None ], dtype = object )
429
+ a1 [0 ] = 3
430
+ a1 [1 ] = ('a' , 30 )
431
+ a1 [2 ] = (None , True , 90000000 )
432
+
433
+ a2 = list (array_to_tuple_iter (a1 ))
434
+ self .assertEqual (a2 , [(3 ,), ('a' , 30 ), (None , True , 90000000 )])
435
+
412
436
413
437
#---------------------------------------------------------------------------
414
438
0 commit comments