L i%*dZddlZddlZddlZddlZddlZddlmZmZ ddl Z ejZ ejZeZ ddlZdZdZdZdZd Zd Zd Zd Zej6dd ZddZdZddZdZ y#e $rdZ Y`wxYw#e $rdZYNwxYw)zFUtilities for fast persistence of big data, with optional compression.N) _COMPRESSORS _ZFILE_PREFIXicPt|d|}t|tjS)z=Check if fileobj is a raw file object, e.g created with open.raw)getattr isinstanceioFileIO)fileobjs _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/joblib/numpy_pickle_utils.py _is_raw_filer&s!gug.G gryy ))ctjDcgc]}t|j}}|ttgz }t |Scc}wN)rvalueslenprefixrmax) compressorprefixess r _get_prefixes_max_lenr,sK9E9L9L9NO:J%%&OHO ]#$$H x=PsAcbtjdk(xr|jjdk(xsg|jjdk(xrL|jjxr4t d|jjj Dxstjdk(xr|jjdk(xsg|jjdk(xrL|jjxr4t d|jjj DS)z2Check if numpy array is having byte order mismatchbig<|c3@K|]}|djdk(yw)rrN byteorder.0es r z6_is_numpy_array_byte_order_mismatch..<S!!#-Slittle>c3@K|]}|djdk(yw)rr'Nrr s r r#z6_is_numpy_array_byte_order_mismatch..Fr$r%)sysrdtypefieldsallrarrays r #_is_numpy_array_byte_order_mismatchr/3s  KK ! !S (  %%,TKK&&TSu{{7I7I7P7P7RSS  ! KK ! !S (  %%,TKK&&TSu{{7I7I7P7P7RSS#rct|r8|jj|jj d}|S)zzUse the byte order of the host while preserving values Does nothing if array already uses the system byte order. =)r/byteswapviewr* newbyteorderr-s r _ensure_native_byte_orderr5Ls7 +51 %%ekk&>&>s&CD Lrc:t}t|dr|j|}n"|j|}|j d|j t rytjD]$\}}|j |js"|cSy)zReturn the compressor matching fileobj. Parameters ---------- fileobj: file object Returns ------- str in {'zlib', 'gzip', 'bz2', 'lzma', 'xz', 'compat', 'not-compressed'} peekrcompatnot-compressed) rhasattrr7readseek startswithrritemsr)r max_prefix_len first_bytesnamers r _detect_compressorrBXs+,Nwll>2 ll>2  Qm, , 2 2 4  D*%%j&7&78   rc8tj|tS)z0Return a buffered version of a read file object. buffer_size)r BufferedReader_IO_BUFFER_SIZEfobjs r _buffered_read_filerJx  T ??rc8tj|tS)z1Return a buffered version of a write file object.rD)r BufferedWriterrGrHs r _buffered_write_filerN}rKrc#Kt|}|}|dk(r&tjd|ztd||fy|tvr%t|}|j |}t |}|d}t|tjr#tjdtzdnX|dk7r#tjdtzdn0t|s#tjd tzdn|}||fyw) aUtility function opening the right fileobject from a filename. The magic number is used to choose between the type of file object to open: * regular file object (default) * zlib file object * gzip file object * bz2 file object * lzma file object (for xz and lzma compressor) Parameters ---------- fileobj: file object filename: str filename path corresponding to the fileobj parameter. mmap_mode: str memory map mode that should be used to open the pickle file. This parameter is useful to verify that the user is not trying to one with compression. Default: None. Returns ------- a tuple with a file like object, and the validated mmap_mode. r8zjThe file '%s' has been generated with a joblib version less than 0.10. Please regenerate this pickle file.) stacklevelNzuIn memory persistence is not compatible with mmap_mode "%(mmap_mode)s" flag passed. mmap_mode option will be ignored.r9ztmmap_mode "%(mmap_mode)s" is not compatible with compressed file %(filename)s. "%(mmap_mode)s" flag will be ignored.zP"%(fileobj)r" is not a raw file, mmap_mode "%(mmap_mode)s" flag will be ignored.) rBwarningswarnDeprecationWarningrdecompressor_filerJr r BytesIOlocalsr)r filename mmap_modervalidated_mmap_modecompressor_wrapperinsts r _validate_fileobject_and_memmapr]s&6$G,J#X   24< =   +++  %".j!9 %77@D)$/G  "& '2::. 8:@(C !  // <>DhG !  "'* <>DhG  '0#***sDDc|d}|d}|tjvr%t|j||}t|Stdj||}t|S)z6Return the right compressor file object in write mode.rr) compresslevelzlib)rkeyscompressor_filerN)rXcompresscompressmethodr_ file_instances r _write_fileobjectrfs~a[NQKM**,,$^4DD ME $M22$V,<< M= $M22ric&t} |j|t|z }||z }t|dk(st||k(rn Bt||k7rd}t |||t|fz|S#tj$rYBwxYw)aRead from file-like object until size bytes are read. TODO python2_drop: is it still needed? The docstring mentions python 2.6 and it looks like this can be at least simplified ... Raises ValueError if not EOF is encountered before size bytes are read. Non-blocking objects only supported if they derive from io objects. Required as e.g. ZipExtFile in python 2.6 can return less data than requested. This function was taken from numpy/lib/format.py in version 1.10.2. Parameters ---------- fp: file-like object size: int error_template: str Returns ------- a bytes object The data read in bytes. rz)EOF: reading %s, expected %d bytes got %d)bytesr;rr BlockingIOError ValueError)fpsizeerror_templatedatarmsgs r _read_bytesrqs4 7D  s4y()A AID1v{c$i4/0  4yD9c$i@@AA !!   s>A::BBcftjdd}|dk(rddlm}n |dk(rddlm}|i|S)NrPz1.r) _reconstructz2.)np __version__numpy.core.multiarrayrsnumpy._core.multiarray)argskwargsnp_major_versionnp_reconstructs r rsrss; ~~bq)4H T !I 4 *6 **rr))r`)zran out of data)!__doc__ contextlibr pickler)rRrrrnumpyrt ImportError _Unpickler Unpickler_PicklerPicklerrangexrangebz2rGrrr/r5rBrJrNcontextmanagerr]rf BUFFER_SIZErqrsrr rsL  3    //   * 2@@ @  M+M+`3( *Z +M B Cs"A;B;BBBB