Skip to content

Commit

Permalink
fix(raw): replace NaN values by 'NaN' inside output matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Dec 20, 2024
1 parent d8df7e9 commit 13571fa
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ def parse_dataframe(
date, body = self.date_serializer.extract_date(df)

matrix = rename_unnamed(body).astype(float)
matrix = matrix.where(pd.notna(matrix), None)
matrix.index = date
matrix.columns = body.columns
return matrix
# replace NaN values by "NaN" for the front-end
final_matrix = matrix.fillna("NaN")
final_matrix.index = date
final_matrix.columns = body.columns
return final_matrix

def parse(
self,
Expand Down
3 changes: 0 additions & 3 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#
# This file is part of the Antares project.

import math
import time
import uuid
from datetime import datetime, timedelta, timezone
Expand Down Expand Up @@ -79,8 +78,6 @@ def assert_study(a: SUB_JSON, b: SUB_JSON) -> None:
_assert_list(cast(List[float], a.tolist()), b)
elif isinstance(a, list) and isinstance(b, np.ndarray):
_assert_list(a, cast(List[float], b.tolist()))
elif isinstance(a, float) and math.isnan(a):
assert math.isnan(b)
else:
_assert_others(a, b)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def test_get_study_data(self, client: TestClient, user_access_token: str, intern
if study_type == "raw":
res = client.get(raw_url, params={"path": "output/20201014-1427eco/economy/mc-all/areas/de/id-monthly"})
assert res.status_code == 200
assert np.isnan(res.json()["data"][0]).any()
assert "NaN" in res.json()["data"][0]

# Iterate over all possible combinations of path and depth
for path, depth in itertools.product([None, "", "/"], [0, 1, 2]):
Expand Down
14 changes: 6 additions & 8 deletions tests/storage/integration/data/set_id_annual.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#
# This file is part of the Antares project.

import math

set_id_annual = {
"columns": [
("OP. COST", "Euro", "min"),
Expand Down Expand Up @@ -253,14 +251,14 @@
1.0,
1.0,
1.0,
math.nan,
math.nan,
"NaN",
"NaN",
1.0,
1.0,
math.nan,
math.nan,
math.nan,
math.nan,
"NaN",
"NaN",
"NaN",
"NaN",
1.0,
1.0,
1.0,
Expand Down
Loading

0 comments on commit 13571fa

Please sign in to comment.