Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _read_table(*, connection: tab_api.Connection, table: TableType) -> pd.DataFrame:
if isinstance(table, str):
table = tab_api.TableName(table)
table_def = connection.catalog.get_table_definition(table)
columns = table_def.columns
dtypes: Dict[str, str] = {}
for column in columns:
column_type = pantab_types._ColumnType(column.type, column.nullability)
try:
dtypes[column.name.unescaped] = pantab_types._pandas_types[column_type]
except KeyError as e:
raise TypeError(
f"Column {column.name} has unsupported datatype {column.type}"
) from e
query = f"SELECT * from {table}"
dtype_strs = tuple(dtypes.values())
df = pd.DataFrame(libreader.read_hyper_query(connection._cdata, query, dtype_strs))
df.columns = dtypes.keys()
# TODO: remove this hackery...
for k, v in dtypes.items():
if v == "date":
dtypes[k] = "datetime64[ns]"