44import os
55import pickle
66from contextlib import nullcontext
7+ from pathlib import Path
78from typing import Union , BinaryIO , TYPE_CHECKING , Type , Optional , Generator
89
910from ....helper import (
@@ -24,7 +25,7 @@ class BinaryIOMixin:
2425 @classmethod
2526 def load_binary (
2627 cls : Type ['T' ],
27- file : Union [str , BinaryIO , bytes ],
28+ file : Union [str , BinaryIO , bytes , Path ],
2829 protocol : str = 'pickle-array' ,
2930 compress : Optional [str ] = None ,
3031 _show_progress : bool = False ,
@@ -54,13 +55,14 @@ def load_binary(
5455 file_ctx = nullcontext (file )
5556 elif isinstance (file , bytes ):
5657 file_ctx = nullcontext (file )
58+ # by checking path existence we allow file to be of type Path, LocalPath, PurePath and str
5759 elif os .path .exists (file ):
5860 protocol , compress = protocol_and_compress_from_file_path (
5961 file , protocol , compress
6062 )
6163 file_ctx = open (file , 'rb' )
6264 else :
63- raise ValueError (f'unsupported input { file !r } ' )
65+ raise FileNotFoundError (f'cannot find file { file } ' )
6466 if streaming :
6567 return cls ._load_binary_stream (
6668 file_ctx ,
0 commit comments