Пример #1
0
 def read(self):
     try:
         if self._result:
             return self._result
         if self._files:
             res = {}
             for src, filename, fileno, txt in self._files:
                 self._src = src
                 self._file = filename
                 self._fileno = fileno
                 self._txt = txt
                 self._colnames = None
                 try:
                     _dt = core.gread(self)
                     dt = Frame(_dt, names=self._colnames)
                     res[src] = dt
                 except Exception as e:
                     res[src] = e
             return res
         else:
             _dt = core.gread(self)
             dt = Frame(_dt, names=self._colnames)
             return dt
     finally:
         self._clear_temporary_files()
Пример #2
0
 def _process_excel_file(self, filename):
     try:
         import xlrd
     except ImportError:
         raise TValueError("Module `xlrd` is required in order to read "
                           "Excel file '%s'. You can install this module "
                           "by running `pip install xlrd` in the command "
                           "line." % filename)
     if self._result is None:
         self._result = {}
     wb = xlrd.open_workbook(filename)
     for ws in wb.sheets():
         # If the worksheet is empty, skip it
         if ws.ncols == 0:
             continue
         # Assume first row contains headers
         colnames = ws.row_values(0)
         cols0 = [core.column_from_list(ws.col_values(i, start_rowx=1),
                                        -stype.str32.value)
                  for i in range(ws.ncols)]
         colset = core.columns_from_columns(cols0)
         res = Frame(colset.to_datatable(), names=colnames)
         self._result[ws.name] = res
     if len(self._result) == 0:
         self._result = None
     if len(self._result) == 1:
         self._result = [*self._result.values()][0]
Пример #3
0
 def read(self):
     if self._result:
         return self._result
     _dt = core.gread(self)
     dt = Frame(_dt, names=self._colnames)
     if self._tempfile:
         if self._verbose:
             self.logger.debug("Removing temporary file %s" %
                               self._tempfile)
         try:
             os.remove(self._tempfile)
             os.rmdir(self._tempdir)
         except OSError as e:
             self.logger.warning("Failed to remove temporary files: %r" % e)
     return dt