def _from_json_index(state: DataFrameState, table: dict): if state.columns is None: # make header state.columns = { k: i for i, k in enumerate(next(iter(table.values())).keys()) } for row in table.keys(): yield csv_row(td for td in table[row].values()) else: for row in table.keys(): yield csv_row(table[row][col] for col in state.columns)
def _from_json_split(state: DataFrameState, table: dict): table_columns = {k: i for i, k in enumerate(table['columns'])} if state.columns is None: # make header state.columns = table_columns for row in table['data']: yield csv_row(row) else: idxs = [state.columns[k] for k in table_columns] for row in table['data']: yield csv_row(row[idx] for idx in idxs)
def _from_csv_without_index(state: DataFrameState, table: Iterator[str]): row_str = next(table) # skip column names table_columns = tuple(csv_unquote(s) for s in csv_split(row_str, ',')) if state.columns is None: state.columns = table_columns for row_str in table: if not row_str: # skip blank line continue if not row_str.strip(): yield csv_quote(row_str) else: yield row_str elif not all( c1 == c2 for c1, c2 in itertools.zip_longest(state.columns, table_columns)): idxs = [state.columns[k] for k in table_columns] for row_str in table: if not row_str: # skip blank line continue if not row_str.strip(): yield csv_quote(row_str) else: tr = tuple(s for s in csv_split(row_str, ",")) yield csv_row(tr[i] for i in idxs) else: for row_str in table: if not row_str: # skip blank line continue if not row_str.strip(): yield csv_quote(row_str) else: yield row_str
def _from_json_columns(state: DataFrameState, table: dict): if state.columns is None: # make header state.columns = {k: i for i, k in enumerate(table.keys())} for row in next(iter(table.values())): yield csv_row(table[col][row] for col in state.columns)
def _from_json_values(_: DataFrameState, table: list): for tr in table: yield csv_row(tr)
def _from_json_records(state: DataFrameState, table: list): if state.columns is None: # make header state.columns = {k: i for i, k in enumerate(table[0].keys())} for tr in table: yield csv_row(tr[c] for c in state.columns)