Skip to content

Commit 2c64f6e

Browse files
committed
scientific notation formatting
1 parent 90cd416 commit 2c64f6e

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

ibis-server/app/util.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ def _to_datetime_and_format(series: pd.Series) -> pd.Series:
2929

3030

3131
def _to_json_obj(df: pd.DataFrame) -> dict:
32-
data = df.map(lambda x: f"{x:.9g}" if isinstance(x, float) else x).to_dict(
33-
orient="split", index=False
34-
)
32+
data = df.map(
33+
lambda x: f"{x:.9g}"
34+
if isinstance(x, float)
35+
else f"{x:.3f}"
36+
if isinstance(x, decimal.Decimal)
37+
else x
38+
).to_dict(orient="split")
3539

3640
def default(obj):
3741
if pd.isna(obj):

ibis-server/tests/routers/v2/connector/test_bigquery.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,20 @@ async def test_query_values(client, manifest_str):
198198
assert response.status_code == 204
199199

200200

201+
async def test_scientific_notation(client, manifest_str):
202+
response = await client.post(
203+
url=f"{base_url}/query",
204+
json={
205+
"connectionInfo": connection_info,
206+
"manifestStr": manifest_str,
207+
"sql": "SELECT cast(0 as numeric) as col",
208+
},
209+
)
210+
assert response.status_code == 200
211+
result = response.json()
212+
assert result["data"][0] == ["0.000"]
213+
214+
201215
async def test_query_empty_json(client, manifest_str):
202216
"""Test the empty result with json column."""
203217
response = await client.post(

0 commit comments

Comments
 (0)