45
45
_write_data ,
46
46
_ftype4scaled_finite ,
47
47
)
48
- from ..openers import Opener , BZ2File , HAVE_ZSTD
48
+ from ..openers import Opener , BZ2File
49
49
from ..casting import (floor_log2 , type_info , OK_FLOATS , shared_range )
50
50
51
51
from ..deprecator import ExpiredDeprecationError
52
+ from ..optpkg import optional_package
52
53
53
54
from numpy .testing import (assert_array_almost_equal ,
54
55
assert_array_equal )
55
56
import pytest
56
57
57
58
from nibabel .testing import nullcontext , assert_dt_equal , assert_allclose_safely , suppress_warnings
58
59
59
- # only import ZstdFile, if installed
60
- if HAVE_ZSTD :
61
- from ..openers import ZstdFile
60
+ pyzstd , HAVE_ZSTD , _ = optional_package ("pyzstd" )
62
61
63
62
#: convenience variables for numpy types
64
63
FLOAT_TYPES = np .sctypes ['float' ]
@@ -76,7 +75,7 @@ def test__is_compressed_fobj():
76
75
('.gz' , gzip .open , True ),
77
76
('.bz2' , BZ2File , True )]
78
77
if HAVE_ZSTD :
79
- file_openers += [('.zst' , ZstdFile , True )]
78
+ file_openers += [('.zst' , pyzstd . ZstdFile , True )]
80
79
for ext , opener , compressed in file_openers :
81
80
fname = 'test.bin' + ext
82
81
for mode in ('wb' , 'rb' ):
@@ -100,7 +99,7 @@ def make_array(n, bytes):
100
99
with InTemporaryDirectory ():
101
100
openers = [open , gzip .open , BZ2File ]
102
101
if HAVE_ZSTD :
103
- openers += [ZstdFile ]
102
+ openers += [pyzstd . ZstdFile ]
104
103
for n , opener in itertools .product (
105
104
(256 , 1024 , 2560 , 25600 ),
106
105
openers ):
@@ -266,7 +265,7 @@ def test_array_from_file_reread():
266
265
with InTemporaryDirectory ():
267
266
openers = [open , gzip .open , bz2 .BZ2File , BytesIO ]
268
267
if HAVE_ZSTD :
269
- openers += [ZstdFile ]
268
+ openers += [pyzstd . ZstdFile ]
270
269
for shape , opener , dtt , order in itertools .product (
271
270
((64 ,), (64 , 65 ), (64 , 65 , 66 )),
272
271
openers ,
0 commit comments