4545 _write_data ,
4646 _ftype4scaled_finite ,
4747 )
48- from ..openers import Opener , BZ2File , HAVE_ZSTD
48+ from ..openers import Opener , BZ2File
4949from ..casting import (floor_log2 , type_info , OK_FLOATS , shared_range )
5050
5151from ..deprecator import ExpiredDeprecationError
52+ from ..optpkg import optional_package
5253
5354from numpy .testing import (assert_array_almost_equal ,
5455 assert_array_equal )
5556import pytest
5657
5758from nibabel .testing import nullcontext , assert_dt_equal , assert_allclose_safely , suppress_warnings
5859
59- # only import ZstdFile, if installed
60- if HAVE_ZSTD :
61- from ..openers import ZstdFile
60+ pyzstd , HAVE_ZSTD , _ = optional_package ("pyzstd" )
6261
6362#: convenience variables for numpy types
6463FLOAT_TYPES = np .sctypes ['float' ]
@@ -76,7 +75,7 @@ def test__is_compressed_fobj():
7675 ('.gz' , gzip .open , True ),
7776 ('.bz2' , BZ2File , True )]
7877 if HAVE_ZSTD :
79- file_openers += [('.zst' , ZstdFile , True )]
78+ file_openers += [('.zst' , pyzstd . ZstdFile , True )]
8079 for ext , opener , compressed in file_openers :
8180 fname = 'test.bin' + ext
8281 for mode in ('wb' , 'rb' ):
@@ -100,7 +99,7 @@ def make_array(n, bytes):
10099 with InTemporaryDirectory ():
101100 openers = [open , gzip .open , BZ2File ]
102101 if HAVE_ZSTD :
103- openers += [ZstdFile ]
102+ openers += [pyzstd . ZstdFile ]
104103 for n , opener in itertools .product (
105104 (256 , 1024 , 2560 , 25600 ),
106105 openers ):
@@ -266,7 +265,7 @@ def test_array_from_file_reread():
266265 with InTemporaryDirectory ():
267266 openers = [open , gzip .open , bz2 .BZ2File , BytesIO ]
268267 if HAVE_ZSTD :
269- openers += [ZstdFile ]
268+ openers += [pyzstd . ZstdFile ]
270269 for shape , opener , dtt , order in itertools .product (
271270 ((64 ,), (64 , 65 ), (64 , 65 , 66 )),
272271 openers ,
0 commit comments