ó
¤>dc           @   sP   d  d l  Z  d  d l Z d  d l m Z d „  Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿN(   t   parse_versionc           C   s[   t  t j ƒ t  d ƒ k  rW t  t j ƒ t  d ƒ k rW t d j t j t j ƒ ƒ ‚ n  d  S(   Ns   2.7s   1.13sœ   Incompatible h5py=={} and numpy=={} versions detected. 
Array reading/decoding may not proceed as expected. 
Please upgrade to the latest compatible verions(   R    t   h5pyt   __version__t   npt   EnvironmentErrort   format(    (    (    sH   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/data_sanitisation.pyt   check_version_compatibility   s    	c         C   s®   t  |  t j ƒ rG |  j j d k r: t j j |  ƒ j ƒ  S|  j ƒ  Snc t |  ƒ j	 t j
 k r |  j ƒ  } t  | t ƒ r‰ | j ƒ  } n  | St  |  t ƒ r¦ |  j ƒ  S|  Sd S(   s:    Convert numpy numeric types to their python equivalents. t   SN(   t
   isinstanceR   t   ndarrayt   dtypet   kindt   chart   decodet   tolistt   typet
   __module__t   __name__t   itemt   bytes(   t   valuet
   conversion(    (    sH   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/data_sanitisation.pyt   _clean   s    
c         C   sl  t  ƒ  t |  t ƒ r  |  j ƒ  St |  t j ƒ r] |  j j t j t j ƒ k r] |  j	 d ƒ St |  t j ƒ rht
 |  j ƒ d k rhg  } xw |  j j D]i } |  j j | \ } } | j d k rí | j | j } t j d j | ƒ ƒ } n  | j | | f ƒ q— Wy |  j	 | ƒ SWqht t f k
 rdt t j ƒ t d ƒ k  r^t d j | ƒ ƒ ‚ qe‚  qhXn  |  S(   NR   i   t   Us   |S{}s   2.7sH  Cannot encode array with types: {}.
There are known bugs in h5py<2.7 which yield non-deteministic results when decoding arrays with empty strings and additional bugs with compatibility between h5py<2.7 and numpy>=1.13 when decoding arrays with  mixed/padded data types.
Please try upgrading to the latest h5py and numpy versions(   R   R   t   strt   encodeR   R	   R
   R   t   unicodet   astypet   lent   namest   fieldst   itemsizet	   alignmentR   t   appendt
   ValueErrort   UnicodeEncodeErrorR    R   R   t   UnicodeError(   t   datat   encoded_dtypest
   field_namet   field_dtypet   field_byte_indext   str_len(    (    sH   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/data_sanitisation.pyt   _sanitize_data_for_writing$   s*    
0'	
c         C   su  t  ƒ  t |  t j ƒ r& |  d }  n  t |  t ƒ r? |  j ƒ  St |  t j ƒ rs |  j j	 d k rs t j
 j |  ƒ St |  t j ƒ rqt |  j ƒ d k rqg  } xj |  j j D]\ } |  j j | \ } } | j	 d k rö t j d j | j ƒ ƒ } n  | j | | f ƒ q­ Wy |  j | ƒ SWqqt t f k
 rmt t j ƒ t d ƒ k  rgt d j | ƒ ƒ ‚ qn‚  qqXn  |  S(   NR   i   s   <U{}s   2.7sH  Cannot encode array with types: {}.
There are known bugs in h5py<2.7 which yield non-deteministic results when decoding arrays with empty strings and additional bugs with compatibility between h5py<2.7 and numpy>=1.13 when decoding arrays with  mixed/padded data types.
Please try upgrading to the latest h5py and numpy versions(    (   R   R   R   t   DatasetR   R   R   R	   R
   R   R   R   R   R   R   R   R!   R   t   UnicodeDecodeErrort   SystemErrorR    R   R$   (   R%   t   decoded_dtypesR'   R(   R)   (    (    sH   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/data_sanitisation.pyt   _sanitize_data_for_readingE   s,    
$'	
(	   R   t   numpyR   t   pkg_resourcesR    R   R   R+   R0   (    (    (    sH   /tmp/pip-install-m8tpmx/ont-fast5-api/ont_fast5_api/data_sanitisation.pyt   <module>   s   				!