Skip to content

Commit

Permalink
only handel special case 0
Browse files Browse the repository at this point in the history
  • Loading branch information
douenergy committed Feb 25, 2025
1 parent 2c64f6e commit 4bca438
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions ibis-server/app/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ def _to_datetime_and_format(series: pd.Series) -> pd.Series:


def _to_json_obj(df: pd.DataFrame) -> dict:
data = df.map(
lambda x: f"{x:.9g}"
if isinstance(x, float)
else f"{x:.3f}"
if isinstance(x, decimal.Decimal)
else x
).to_dict(orient="split")
def format_value(x):
if isinstance(x, float):
# Special case for zero to avoid scientific notation
if x == 0:
return "0"
return f"{x:.9g}"
else:
return x

data = df.map(format_value).to_dict(orient="split", index=False)

def default(obj):
if pd.isna(obj):
Expand Down
2 changes: 1 addition & 1 deletion ibis-server/tests/routers/v2/connector/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ async def test_scientific_notation(client, manifest_str):
)
assert response.status_code == 200
result = response.json()
assert result["data"][0] == ["0.000"]
assert result["data"][0] == ["0"]


async def test_query_empty_json(client, manifest_str):
Expand Down

0 comments on commit 4bca438

Please sign in to comment.