Ejemplo n.º 1
0
Archivo: io.py Proyecto: k1o0/ibllib
def load_file_content(fil):
    """
    Returns content of files. Designed for very generic file formats:
    so far supported contents are `json`, `npy`, `csv`, `tsv`, `ssv`, `jsonable`

    :param fil: file to read
    :return:array/json/pandas dataframe depending on format
    """
    if not fil:
        return
    fil = Path(fil)
    if fil.stat().st_size == 0:
        return
    if fil.suffix == '.csv':
        return pd.read_csv(fil)
    if fil.suffix == '.json':
        try:
            with open(fil) as _fil:
                return json.loads(_fil.read())
        except Exception as e:
            _logger.error(e)
            return None
    if fil.suffix == '.jsonable':
        return jsonable.read(fil)
    if fil.suffix == '.npy':
        return np.load(file=fil)
    if fil.suffix == '.pqt':
        return parquet.load(fil)
    if fil.suffix == '.ssv':
        return pd.read_csv(fil, delimiter=' ')
    if fil.suffix == '.tsv':
        return pd.read_csv(fil, delimiter='\t')
    return Path(fil)
Ejemplo n.º 2
0
 def __init__(self,
              username=None,
              password=None,
              base_url=None,
              cache_dir=None,
              silent=None):
     # get parameters override if inputs provided
     self._par = oneibl.params.get(silent=silent)
     # can delete those 2 lines from mid January 2021
     if self._par.HTTP_DATA_SERVER == 'http://ibl.flatironinstitute.org':
         self._par = self._par.set("HTTP_DATA_SERVER",
                                   "https://ibl.flatironinstitute.org")
     self._par = self._par.set('ALYX_LOGIN', username
                               or self._par.ALYX_LOGIN)
     self._par = self._par.set('ALYX_URL', base_url or self._par.ALYX_URL)
     self._par = self._par.set('ALYX_PWD', password or self._par.ALYX_PWD)
     self._par = self._par.set('CACHE_DIR', cache_dir
                               or self._par.CACHE_DIR)
     # init the cache file
     self._cache_file = Path(
         self._par.CACHE_DIR).joinpath('.one_cache.parquet')
     if self._cache_file.exists():
         # we need to keep this part fast enough for transient objects
         self._cache = parquet.load(self._cache_file)
     else:
         self._cache = pd.DataFrame()
Ejemplo n.º 3
0
 def __init__(self, username=None, password=None, base_url=None, cache_dir=None, silent=None):
     # get parameters override if inputs provided
     self._par = oneibl.params.get(silent=silent)
     self._par = self._par.set('ALYX_LOGIN', username or self._par.ALYX_LOGIN)
     self._par = self._par.set('ALYX_URL', base_url or self._par.ALYX_URL)
     self._par = self._par.set('ALYX_PWD', password or self._par.ALYX_PWD)
     self._par = self._par.set('CACHE_DIR', cache_dir or self._par.CACHE_DIR)
     # init the cache file
     self._cache_file = Path(self._par.CACHE_DIR).joinpath('.one_cache.parquet')
     if self._cache_file.exists():
         # we need to keep this part fast enough for transient objects
         self._cache = parquet.load(self._cache_file)
     else:
         self._cache = pd.DataFrame()