Skip to content

Commit 3b9f751

Browse files
committed
[evaluation] set timeout to 1h and fix issue with join operation
1 parent 4491bf9 commit 3b9f751

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/evaluate.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
logger = logging.getLogger(__name__)
2828

2929
API_URL = "https://codification-ape-graph-rag-api.lab.sspcloud.fr"
30+
TIMEOUT = 3600
3031

3132

3233
async def evaluate_method(
@@ -49,7 +50,6 @@ async def evaluate_method(
4950
elapsed_td = datetime.timedelta(seconds=elapsed_seconds)
5051

5152
response.raise_for_status()
52-
5353
preds = process_response(response.json())
5454
preds_levels = get_all_levels(preds, df_naf, "code_ape")
5555
save_predictions(preds, method)
@@ -66,8 +66,22 @@ async def evaluate_method(
6666
logger.info(f"✅ Finished evaluation for '{method}'")
6767
return preds_levels
6868

69+
except httpx.TimeoutException:
70+
logger.error(
71+
f"⏳ Timeout during '{method}': Request took more than {humanize.precisedelta(datetime.timedelta(seconds=TIMEOUT))}"
72+
)
73+
return pd.DataFrame()
74+
75+
except httpx.HTTPStatusError as http_exc:
76+
logger.error(f"🚨 HTTP error during '{method}': {http_exc.response.status_code} - {http_exc.response.text}")
77+
return pd.DataFrame()
78+
79+
except httpx.RequestError as req_exc:
80+
logger.error(f"📡 Network error during '{method}': {type(req_exc).__name__} - {req_exc}")
81+
return pd.DataFrame()
82+
6983
except Exception as e:
70-
logger.error(f"❌ Error during '{method}': {e}")
84+
logger.error(f"❌ Unexpected error during '{method}': {type(e).__name__} - {e}")
7185
return pd.DataFrame()
7286

7387

@@ -77,7 +91,7 @@ async def evaluate_all(
7791
df_naf: pd.DataFrame,
7892
ground_truth: pd.DataFrame,
7993
) -> List[pd.DataFrame]:
80-
async with httpx.AsyncClient() as client:
94+
async with httpx.AsyncClient(timeout=httpx.Timeout(TIMEOUT)) as client:
8195
tasks = [evaluate_method(client, method, queries, df_naf, ground_truth) for method in methods]
8296
return await asyncio.gather(*tasks)
8397

@@ -108,7 +122,7 @@ async def evaluate_all(
108122
else:
109123

110124
async def eval_single():
111-
async with httpx.AsyncClient() as client:
125+
async with httpx.AsyncClient(timeout=httpx.Timeout(TIMEOUT)) as client:
112126
return await evaluate_method(client, methods[0], queries, df_naf, ground_truth)
113127

114128
asyncio.run(eval_single())

src/evaluation/data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def load_test_data(num_samples: int) -> pd.DataFrame:
1212

1313

1414
def get_all_levels(df: pd.DataFrame, df_naf: pd.DataFrame, col: str) -> pd.DataFrame:
15-
return df[[col]].merge(df_naf, left_on=col, right_on="APE_NIV5")[df_naf.columns.drop(["LIB_NIV5"])]
15+
# Invalid NAF2025 code are replaced by NaN here (with how="left")
16+
return df[[col]].merge(df_naf, how="left", left_on=col, right_on="APE_NIV5")[df_naf.columns.drop(["LIB_NIV5"])]
1617

1718

1819
def process_response(raw_response: List[dict]) -> pd.DataFrame:

0 commit comments

Comments
 (0)