@@ -792,8 +792,9 @@ def test_image_compression_nulls_patches_with_subnormal(
792792 # however, on read, we send nullcheck=NAN and as a side
793793 # effect the subnormal float value in this row gets truncated
794794 # to zero
795- np .testing .assert_array_equal (read_data [1 , 1 :], 0.0 )
796- np .testing .assert_array_equal (read_slice1 [1 :], 0.0 )
795+ if not cfitsio_is_bundled ():
796+ np .testing .assert_array_equal (read_data [1 , 1 :], 0.0 )
797+ np .testing .assert_array_equal (read_slice1 [1 :], 0.0 )
797798
798799 # this does not happen for row index 2 which doesn't have
799800 # subnormal float values
@@ -887,6 +888,27 @@ def test_image_compression_read_from_osx_arm64():
887888 np .testing .assert_array_equal (data , cdata )
888889
889890
891+ def test_image_compression_gzip_subnormal_cast_to_zero ():
892+ # test code from astrofrog in https://github.com/esheldon/fitsio/issues/513
893+ data = np .zeros (
894+ (5 , 1 ), dtype = '>f4'
895+ ) # a single 5x1 tile, big-endian float32
896+ data [:, 0 ] = [134.97459 , 248.02034 , 183.40105 , 57.59670 , 216.31425 ]
897+
898+ with tempfile .TemporaryDirectory () as tmpdir :
899+ fn = os .path .join (tmpdir , "mini.fit" )
900+ with FITS (fn , "rw" ) as f :
901+ f .write (
902+ data , compress = "GZIP_1" , tile_dims = (5 , 1 ), qlevel = 5 , qmethod = - 1
903+ )
904+
905+ back = read (fn )
906+ if cfitsio_is_bundled ():
907+ assert not back .ravel ()[0 ] == 0 , back .ravel ()
908+ else :
909+ assert back .ravel ()[0 ] == 0 , back .ravel ()
910+
911+
890912if __name__ == '__main__' :
891913 test_compressed_seed (
892914 compress = 'rice' ,
0 commit comments