Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(matrix): remove columns full of NaN inside matrices at the import #2287

Merged
merged 3 commits into from
Jan 9, 2025
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
1 change: 1 addition & 0 deletions antarest/study/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,7 @@ def _create_edit_study_command(
# Can happen with data with only one column. In this case, we don't care about the delimiter.
delimiter = "\t"
df = pd.read_csv(io.BytesIO(data), delimiter=delimiter, header=None).replace(",", ".", regex=True)
df = df.dropna(axis=1, how="all") # We want to remove columns full of NaN at the import
matrix = df.to_numpy(dtype=np.float64)
matrix = matrix.reshape((1, 0)) if matrix.size == 0 else matrix
return ReplaceMatrix(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,20 @@ def test_get_study_data(self, client: TestClient, user_access_token: str, intern
b"\xef\xbb\xbf1;1;1;1;1\r\n1;1;1;1;1",
b"1;1;1;1;1\r1;1;1;1;1",
b"0,000000;0,000000;0,000000;0,000000\n0,000000;0,000000;0,000000;0,000000",
b"1;2;3;;;\n4;5;6;;;\n",
],
["\t", "\t", ",", "\t", ";", ";", ";"],
["\t", "\t", ",", "\t", ";", ";", ";", ";"],
):
res = client.put(raw_url, params={"path": matrix_path}, files={"file": io.BytesIO(content)})
assert res.status_code == 204, res.json()
res = client.get(raw_url, params={"path": matrix_path})
written_data = res.json()["data"]
if not content.decode("utf-8"):
# For some reason the `GET` returns the default matrix when it's empty
# The `GET` returns the default matrix when it's empty
expected = 8760 * [[0]] if study_type == "raw" else [[]]
else:
df = pd.read_csv(io.BytesIO(content), delimiter=delimiter, header=None).replace(",", ".", regex=True)
df = df.dropna(axis=1, how="all") # We want to remove columns full of NaN at the import
expected = df.to_numpy(dtype=np.float64).tolist()
assert written_data == expected

Expand Down
Loading