File tree Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -140,15 +140,21 @@ def to_filename(fname: str | Path, x5_list: List[X5Transform]):
140140
141141def from_filename (fname : str | Path ) -> List [X5Transform ]:
142142 """Read a list of :class:`X5Transform` objects from an X5 HDF5 file."""
143- with h5py .File (str (fname ), "r" ) as in_file :
144- if in_file .attrs .get ("Format" ) != "X5" :
145- raise ValueError ("Input file is not in X5 format" )
146-
147- tg = in_file ["TransformGroup" ]
148- return [
149- _read_x5_group (node )
150- for _ , node in sorted (tg .items (), key = lambda kv : int (kv [0 ]))
151- ]
143+ try :
144+ with h5py .File (str (fname ), "r" ) as in_file :
145+ if in_file .attrs .get ("Format" ) != "X5" :
146+ raise TypeError ("Input file is not in X5 format" )
147+
148+ tg = in_file ["TransformGroup" ]
149+ return [
150+ _read_x5_group (node )
151+ for _ , node in sorted (tg .items (), key = lambda kv : int (kv [0 ]))
152+ ]
153+ except OSError as err :
154+ if "file signature not found" in err .args [0 ]:
155+ raise TypeError ("Input file is not HDF5." )
156+
157+ raise
152158
153159
154160def _read_x5_group (node ) -> X5Transform :
Original file line number Diff line number Diff line change @@ -73,5 +73,5 @@ def test_from_filename_invalid(tmp_path):
7373 with H5File (fname , "w" ) as f :
7474 f .attrs ["Format" ] = "NOTX5"
7575
76- with pytest .raises (ValueError ):
76+ with pytest .raises (TypeError ):
7777 from_filename (fname )
You can’t perform that action at this time.
0 commit comments