@@ -476,6 +476,90 @@ def test_exc(self):
476
476
dtype = [('a' , 'i' ), ('b' , 'f' )], fillvalue = 42 )
477
477
478
478
479
+ class TestFillTime (BaseDataset ):
480
+
481
+ """
482
+ Feature: Datasets created with specified fill time property
483
+ """
484
+
485
+ def test_fill_time_default (self ):
486
+ """ Fill time default to IFSET """
487
+ dset = self .f .create_dataset ('foo' , (10 ,), fillvalue = 4.0 )
488
+ plist = dset .id .get_create_plist ()
489
+ self .assertEqual (plist .get_fill_time (), h5py .h5d .FILL_TIME_IFSET )
490
+ self .assertEqual (dset [0 ], 4.0 )
491
+ self .assertEqual (dset [7 ], 4.0 )
492
+
493
+ @ut .skipIf ('gzip' not in h5py .filters .encode , "DEFLATE is not installed" )
494
+ def test_compressed_default (self ):
495
+ """ Fill time is IFSET for compressed dataset (chunked) """
496
+ dset = self .f .create_dataset ('foo' , (10 ,), compression = 'gzip' ,
497
+ fillvalue = 4.0 )
498
+ plist = dset .id .get_create_plist ()
499
+ self .assertEqual (plist .get_fill_time (), h5py .h5d .FILL_TIME_IFSET )
500
+ self .assertEqual (dset [0 ], 4.0 )
501
+ self .assertEqual (dset [7 ], 4.0 )
502
+
503
+ def test_fill_time_never (self ):
504
+ """ Fill time set to NEVER """
505
+ dset = self .f .create_dataset ('foo' , (10 ,), fillvalue = 4.0 ,
506
+ fill_time = 'never' )
507
+ plist = dset .id .get_create_plist ()
508
+ self .assertEqual (plist .get_fill_time (), h5py .h5d .FILL_TIME_NEVER )
509
+ # should not be equal to the explicitly set fillvalue
510
+ self .assertNotEqual (dset [0 ], 4.0 )
511
+ self .assertNotEqual (dset [7 ], 4.0 )
512
+
513
+ def test_fill_time_alloc (self ):
514
+ """ Fill time explicitly set to ALLOC """
515
+ dset = self .f .create_dataset ('foo' , (10 ,), fillvalue = 4.0 ,
516
+ fill_time = 'alloc' )
517
+ plist = dset .id .get_create_plist ()
518
+ self .assertEqual (plist .get_fill_time (), h5py .h5d .FILL_TIME_ALLOC )
519
+
520
+ def test_fill_time_ifset (self ):
521
+ """ Fill time explicitly set to IFSET """
522
+ dset = self .f .create_dataset ('foo' , (10 ,), chunks = (2 ,), fillvalue = 4.0 ,
523
+ fill_time = 'ifset' )
524
+ plist = dset .id .get_create_plist ()
525
+ self .assertEqual (plist .get_fill_time (), h5py .h5d .FILL_TIME_IFSET )
526
+
527
+ def test_invalid_fill_time (self ):
528
+ """ Choice of fill_time is 'alloc', 'never', 'ifset' """
529
+ with self .assertRaises (ValueError ):
530
+ dset = self .f .create_dataset ('foo' , (10 ,), fill_time = 'fill_bad' )
531
+
532
+ def test_non_str_fill_time (self ):
533
+ """ fill_time must be a string """
534
+ with self .assertRaises (ValueError ):
535
+ dset = self .f .create_dataset ('foo' , (10 ,), fill_time = 2 )
536
+
537
+ def test_resize_chunk_fill_time_default (self ):
538
+ """ The resize dataset will be filled (by default fill value 0) """
539
+ dset = self .f .create_dataset ('foo' , (50 , ), maxshape = (100 , ),
540
+ chunks = (5 , ))
541
+ plist = dset .id .get_create_plist ()
542
+ self .assertEqual (plist .get_fill_time (), h5py .h5d .FILL_TIME_IFSET )
543
+
544
+ assert np .isclose (dset [:], 0.0 ).all ()
545
+
546
+ dset .resize ((100 , ))
547
+ assert np .isclose (dset [:], 0.0 ).all ()
548
+
549
+ def test_resize_chunk_fill_time_never (self ):
550
+ """ The resize dataset won't be filled """
551
+ dset = self .f .create_dataset ('foo' , (50 , ), maxshape = (100 , ),
552
+ fillvalue = 4.0 , fill_time = 'never' ,
553
+ chunks = (5 , ))
554
+ plist = dset .id .get_create_plist ()
555
+ self .assertEqual (plist .get_fill_time (), h5py .h5d .FILL_TIME_NEVER )
556
+
557
+ assert not np .isclose (dset [:], 4.0 ).any ()
558
+
559
+ dset .resize ((100 , ))
560
+ assert not np .isclose (dset [:], 4.0 ).any ()
561
+
562
+
479
563
@pytest .mark .parametrize ('dt,expected' , [
480
564
(int , 0 ),
481
565
(np .int32 , 0 ),
0 commit comments