Creates a new TableFu instance from a file or path
186555
def from_file(fn, **options):
        
        if hasattr(fn, 'read'):
            return TableFu(fn, **options)
        with open(fn) as f:
            return TableFu(f, **options)
1019432
def from_stream(cls, f, **kwargs):
        """"""
        lines = lines_from_stream(f)
        if 'meta' not in kwargs:
            kwargs['meta'] = {'from': 'stream'}
        kwargs['meta']['filepath'] = f.name if hasattr(f, 'name') else None
        return cls(lines, **kwargs)
223447
def import_from_json(filename_or_fobj, encoding="utf-8", *args, **kwargs):
    

    source = Source.from_file(filename_or_fobj, mode="rb", plugin_name="json", encoding=encoding)

    json_obj = json.load(source.fobj, encoding=source.encoding)
    field_names = list(json_obj[0].keys())
    table_rows = [[item[key] for key in field_names] for item in json_obj]

    meta = {"imported_from": "json", "source": source}
    return create_table([field_names] + table_rows, meta=meta, *args, **kwargs)
754716
def write_table_to_file(self, dtype, custom_name=None, append=False, dir_path=None):
        
        if custom_name:
            fname = custom_name
        else:
            fname = self.filenames[dtype]
        if not dir_path:
            dir_path=self.directory
        if dtype in self.tables:
            write_df = self.remove_names(dtype)
            outfile = self.tables[dtype].write_magic_file(custom_name=fname,
                                                          dir_path=dir_path,
                                                          append=append, df=write_df)
        return outfile
986301
def new(localfile, jottapath, JFS):
    """"""
    with open(localfile) as lf:
        _new = JFS.up(jottapath, lf)
    return _new
934396
def _fromfile(self):
        """"""
        self._fd.seek(0)
        try:
            self.byte_order = {b'II': '<', b'MM': '>'}[self._fd.read(2)]
        except KeyError:
            raise ValueError("not a valid TIFF file")
        version = struct.unpack(self.byte_order+'H', self._fd.read(2))[0]
        if version == 43:  # BigTiff
            self.offset_size, zero = struct.unpack(self.byte_order+'HH',
                                                   self._fd.read(4))
            if zero or self.offset_size != 8:
                raise ValueError("not a valid BigTIFF file")
        elif version == 42:
            self.offset_size = 4
        else:
            raise ValueError("not a TIFF file")
        self.pages = []
        while True:
            try:
                page = TIFFpage(self)
                self.pages.append(page)
            except StopIteration:
                break
        if not self.pages:
            raise ValueError("empty TIFF file")
562297
def _read_table_file(self, table_file):
        """"""
        self._table_file = table_file
        if os.path.exists(self._table_file):
            self._table = Table.read(self._table_file)
        else:
            self._table = FileHandle.make_table({})
        self._fill_cache()
314104
def from_file(cls, f):
        

        with open_file_like(f, 'r') as fp:
            return cls(json.load(fp))
791641
def fromfile(cls, f):
        """"""
        filter = cls()
        filter._setup(*unpack(cls.FILE_FMT, f.read(calcsize(cls.FILE_FMT))))
        nfilters, = unpack(b'<l', f.read(calcsize(b'<l')))
        if nfilters > 0:
            header_fmt = b'<' + b'Q'*nfilters
            bytes = f.read(calcsize(header_fmt))
            filter_lengths = unpack(header_fmt, bytes)
            for fl in filter_lengths:
                filter.filters.append(BloomFilter.fromfile(f, fl))
        else:
            filter.filters = []

        return filter
376576
def create_temporary_table(from_table, name=None, on_commit=None):
    
    from_table = from_table.__table__ if hasattr(from_table, "__table__") else from_table

    name = name or f"temporary_{from_table.name}"

    # copy the origin table into the metadata with the new name.
    temporary_table = copy_table(from_table, name)

    # change create clause to: CREATE TEMPORARY TABLE
    temporary_table._prefixes = list(from_table._prefixes)
    temporary_table._prefixes.append("TEMPORARY")

    # change post create clause to: ON COMMIT DROP
    if on_commit:
        temporary_table.dialect_options["postgresql"].update(
            on_commit=on_commit,
        )

    temporary_table.insert_many = MethodType(insert_many, temporary_table)
    temporary_table.select_from = MethodType(select_from, temporary_table)
    temporary_table.upsert_into = MethodType(upsert_into, temporary_table)

    return temporary_table
275050
def create_from_row(cls, table_row):
        
        kwargs = {}
        for key in table_row.colnames:
            kwargs[key] = table_row[key]
        try:
            return cls(**kwargs)
        except KeyError:
            print(kwargs)
75551
def create_tablefn_map(fns, pqdb, poolnames):
    """"""
    poolmap = {name: pid for (name, pid) in pqdb.get_all_poolnames()}
    pqdb.store_table_files([(poolmap[pool], os.path.basename(fn))
                            for fn, pool in zip(fns, poolnames)])
    return pqdb.get_tablefn_map()
1327299
def _export_table(table, fname):
    """"""
    import os.path as op
    extension = op.splitext(fname.lower())[1]
    if extension == '':
        fname = fname + '.csv'
    table.to_csv(fname, index=None, sep=',', encoding='utf-8',
                 float_format='%.4f', decimal='.')
507959
def from_file(cls, path, **kwargs):
        """"""
        lines = lines_from_file(path)
        if 'meta' not in kwargs:
            kwargs['meta'] = {'from': 'file'}
        kwargs['meta']['filepath'] = path
        return cls(lines, **kwargs)
103921
def create_table(cls, read_throughput=5, write_throughput=5):
        """"""
        table_name = cls.get_table_name()

        raw_throughput = {
            'ReadCapacityUnits': read_throughput,
            'WriteCapacityUnits': write_throughput
        }

        table_schema = []
        table_definitions = []
        seen_attrs = set()
        for key in cls._get_keys():
            table_schema.append(key.schema())
            table_definitions.append(key.definition())
            seen_attrs.add(key.name)

        indexes = []
        global_indexes = []
        for index in cls._get_indexes():
            if issubclass(index, GlobalIndex):
                global_indexes.append(index.schema())
            else:
                indexes.append(index.schema())
            for key in index._keys:
                if key.name not in seen_attrs:
                    table_definitions.append(key.definition())
                    seen_attrs.add(key.name)

        cls._get_connection().create_table(
            table_name=table_name,
            key_schema=table_schema,
            attribute_definitions=table_definitions,
            provisioned_throughput=raw_throughput,
            local_secondary_indexes=indexes or None,
            global_secondary_indexes=global_indexes or None
        )
976977
def save_all(self, path, table_format='txt', sep='\t',
                 table_ext=None, float_format='%.12g'):
        

        if type(path) is str:
            path = path.rstrip('\\')
            path = Path(path)

        path.mkdir(parents=True, exist_ok=True)

        self.save(path=path,
                  table_format=table_format,
                  sep=sep,
                  table_ext=table_ext,
                  float_format=float_format)

        for ext, ext_name in zip(self.get_extensions(data=True),
                                 self.get_extensions()):
            ext_path = path / ext_name

            ext.save(path=ext_path,
                     table_format=table_format,
                     sep=sep,
                     table_ext=table_ext,
                     float_format=float_format)
        return self
871184
def create_or_open_table_at index
      t = self[index]
      t = self[index] = Workbook::Table.new if t == nil
      t.sheet = self
      t
    end