From 0f0a6eb93f160c0ad105d98d992b54c03b5a87e8 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 7 Aug 2024 14:01:24 +0200 Subject: [PATCH] fix code --- antarest/tools/lib.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/antarest/tools/lib.py b/antarest/tools/lib.py index 0e126519ec..472cf9e8e5 100644 --- a/antarest/tools/lib.py +++ b/antarest/tools/lib.py @@ -4,10 +4,11 @@ import shutil from abc import ABC, abstractmethod from pathlib import Path -from typing import List, Optional, Set, Union +from typing import List, Optional, Set, Union, cast from zipfile import ZipFile import numpy as np +import pandas as pd try: # The HTTPX equivalent of `requests.Session` is `httpx.Client`. @@ -88,9 +89,11 @@ def apply_commands( logger.info("Uploading matrices") matrix_dataset: List[str] = [] for matrix_file in matrices_dir.iterdir(): - matrix = np.loadtxt(matrix_file, delimiter="\t", dtype=np.float64, ndmin=2) - matrix = matrix.reshape((1, 0)) if matrix.size == 0 else matrix - matrix_data = matrix.tolist() + if matrix_file.stat().st_size == 0: + matrix_data: List[List[int]] = [[]] + else: + matrix = cast(pd.DataFrame, pd.read_hdf(matrix_file)) + matrix_data = matrix.values.tolist() res = self.session.post(self.build_url("/v1/matrix"), json=matrix_data) res.raise_for_status() matrix_id = res.json()