Fix NaN JSON serialization in summarise_dataframe
Browse files
src/data/data_providers.py
CHANGED
|
@@ -38,6 +38,7 @@ Loose coupling guarantees:
|
|
| 38 |
|
| 39 |
from __future__ import annotations
|
| 40 |
|
|
|
|
| 41 |
import time
|
| 42 |
import traceback
|
| 43 |
from abc import ABC, abstractmethod
|
|
@@ -137,7 +138,8 @@ def summarise_dataframe(df: pd.DataFrame, max_rows: int = 48) -> Dict[str, Any]:
|
|
| 137 |
if isinstance(v, (pd.Timestamp, datetime)):
|
| 138 |
r[k] = str(v)
|
| 139 |
elif isinstance(v, (float, np.floating)):
|
| 140 |
-
|
|
|
|
| 141 |
return {"rows": records, "row_count": len(records)}
|
| 142 |
|
| 143 |
# Summarise
|
|
|
|
| 38 |
|
| 39 |
from __future__ import annotations
|
| 40 |
|
| 41 |
+
import math
|
| 42 |
import time
|
| 43 |
import traceback
|
| 44 |
from abc import ABC, abstractmethod
|
|
|
|
| 138 |
if isinstance(v, (pd.Timestamp, datetime)):
|
| 139 |
r[k] = str(v)
|
| 140 |
elif isinstance(v, (float, np.floating)):
|
| 141 |
+
fv = float(v)
|
| 142 |
+
r[k] = None if (math.isnan(fv) or math.isinf(fv)) else round(fv, 2)
|
| 143 |
return {"rows": records, "row_count": len(records)}
|
| 144 |
|
| 145 |
# Summarise
|