Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions ibis-server/app/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@ 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 x).to_dict(
orient="split", index=False
)
def format_value(x):
if isinstance(x, float):
return f"{x:.9g}"
elif isinstance(x, decimal.Decimal):
if x == 0:
return "0"
else:
return x
else:
return x

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

def default(obj):
if pd.isna(obj):
Expand Down
14 changes: 14 additions & 0 deletions ibis-server/tests/routers/v2/connector/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ async def test_query_values(client, manifest_str):
assert response.status_code == 204


async def test_scientific_notation(client, manifest_str):
response = await client.post(
url=f"{base_url}/query",
json={
"connectionInfo": connection_info,
"manifestStr": manifest_str,
"sql": "SELECT cast(0 as numeric) as col",
},
)
assert response.status_code == 200
result = response.json()
assert result["data"][0] == ["0"]


async def test_query_empty_json(client, manifest_str):
"""Test the empty result with json column."""
response = await client.post(
Expand Down
2 changes: 1 addition & 1 deletion ibis-server/tests/routers/v2/connector/test_local_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ async def test_list_csv_files(client):
assert "type-test" in table_names
# `invalid` will be considered as a one column csv file
assert "invalid" in table_names
columns = result[0]["columns"]
columns = next(filter(lambda x: x["name"] == "type-test-csv", result))["columns"]
assert columns[0]["name"] == "c_bigint"
assert columns[0]["type"] == "INT64"
assert columns[1]["name"] == "c_bit"
Expand Down
Loading