diff --git a/apps/api/src/python/query/bigquery.ts b/apps/api/src/python/query/bigquery.ts index 1a8411a6..72f684e4 100644 --- a/apps/api/src/python/query/bigquery.ts +++ b/apps/api/src/python/query/bigquery.ts @@ -180,6 +180,13 @@ def _briefer_make_bq_query(): df = pd.concat(chunks, ignore_index=True) convert_columns(df, columns_by_type) initial_rows = json.loads(df.head(250).to_json(orient='records', date_format="iso")) + + # convert all values to string to make sure we preserve the python values + # when displaying this data in the browser + for row in initial_rows: + for key in row: + row[key] = str(row[key]) + if columns is None: columns = get_columns(df) @@ -209,6 +216,12 @@ def _briefer_make_bq_query(): if len(initial_rows) < 250: initial_rows = json.loads(df.head(250).to_json(orient='records', date_format="iso")) + # convert all values to string to make sure we preserve the python values + # when displaying this data in the browser + for row in initial_rows: + for key in row: + row[key] = str(row[key]) + columns = get_columns(df) result = { "type": "success", diff --git a/apps/api/src/python/query/duckdb.ts b/apps/api/src/python/query/duckdb.ts index 6436d3d9..9e3d336a 100644 --- a/apps/api/src/python/query/duckdb.ts +++ b/apps/api/src/python/query/duckdb.ts @@ -52,6 +52,13 @@ def _briefer_make_duckdb_query(): df = query.df() rows = json.loads(df.head(250).to_json(orient='records', date_format='iso')) + + # convert all values to string to make sure we preserve the python values + # when displaying this data in the browser + for row in rows: + for key in row: + row[key] = str(row[key]) + columns = [{"name": col, "type": dtype.name} for col, dtype in df.dtypes.items()] for col in columns: dtype = df[col["name"]].dtype diff --git a/apps/api/src/python/query/index.ts b/apps/api/src/python/query/index.ts index c1dddb1b..93da9a58 100644 --- a/apps/api/src/python/query/index.ts +++ b/apps/api/src/python/query/index.ts @@ -337,26 +337,33 @@ export async function readDataframePage( const code = `import json if not ("${dataframeName}" in globals()): - import pandas as pd - try: - ${dataframeName} = pd.read_parquet("/home/jupyteruser/.briefer/query-${queryId}.parquet.gzip") - except: - print(json.dumps({"type": "not-found"})) + import pandas as pd + try: + ${dataframeName} = pd.read_parquet("/home/jupyteruser/.briefer/query-${queryId}.parquet.gzip") + except: + print(json.dumps({"type": "not-found"})) if "${dataframeName}" in globals(): - start = ${page * pageSize} - end = (${page} + 1) * ${pageSize} - rows = ${dataframeName}.iloc[start:end].to_json( - orient="records", date_format="iso" - ) - columns = [{"name": col, "type": dtype.name} for col, dtype in ${dataframeName}.dtypes.items()] - result = { - "type": "success", - "rows": json.loads(rows), - "count": len(${dataframeName}), - "columns": columns - } - print(json.dumps(result))` + start = ${page * pageSize} + end = (${page} + 1) * ${pageSize} + rows = json.loads(${dataframeName}.iloc[start:end].to_json( + orient="records", date_format="iso" + )) + + # convert all values to string to make sure we preserve the python values + # when displaying this data in the browser + for row in rows: + for key in row: + row[key] = str(row[key]) + + columns = [{"name": col, "type": dtype.name} for col, dtype in ${dataframeName}.dtypes.items()] + result = { + "type": "success", + "rows": rows, + "count": len(${dataframeName}), + "columns": columns + } + print(json.dumps(result))` let result: RunQueryResult | null = null let error: Error | null = null diff --git a/apps/api/src/python/query/sqlalchemy.ts b/apps/api/src/python/query/sqlalchemy.ts index 52c10c4a..5496fc35 100644 --- a/apps/api/src/python/query/sqlalchemy.ts +++ b/apps/api/src/python/query/sqlalchemy.ts @@ -159,6 +159,13 @@ def briefer_make_sqlalchemy_query(): df = convert_df(pd.concat([df, chunk], ignore_index=True)) if rows is None: rows = json.loads(df.head(250).to_json(orient='records', date_format="iso")) + + # convert all values to string to make sure we preserve the python values + # when displaying this data in the browser + for row in rows: + for key in row: + row[key] = str(row[key]) + if columns is None: columns = [{"name": col, "type": dtype.name} for col, dtype in chunk.dtypes.items()]