Skip to content

Build and run agents you can see, understand and trust.

fix(rag): keep text and NA-like values intact in ExcelParser (#2893)

DavdGaoabdbc3d5e66a
diff --git a/src/agentscope/rag/_parser/_excel.py b/src/agentscope/rag/_parser/_excel.py
index 5c4643db9..2c133a9e0 100644
--- a/src/agentscope/rag/_parser/_excel.py
+++ b/src/agentscope/rag/_parser/_excel.py
@@ -312,7 +312,12 @@ class ExcelParser(ParserBase):
sheet_sections: list[Section] = []
try:
- df = excel_file.parse(sheet_name=sheet_name)
+ # Keep cell text as-is instead of letting pandas infer types or NAs
+ df = excel_file.parse(
+ sheet_name=sheet_name,
+ dtype=object,
+ keep_default_na=False,
+ )
except Exception as e:
logger.warning("Failed to parse sheet '%s': %s", sheet_name, e)
return sheet_sections
diff --git a/tests/rag_parser_test.py b/tests/rag_parser_test.py
index 5676c22d9..286d49292 100644
--- a/tests/rag_parser_test.py
+++ b/tests/rag_parser_test.py
@@ -1297,6 +1297,35 @@ class ExcelParserTest(IsolatedAsyncioTestCase):
],
)
+ async def test_text_and_na_like_values_kept(self) -> None:
+ """Text like ``"00123"`` and ``"NA"`` is not coerced by pandas."""
+ xlsx_bytes = _make_xlsx_simple(
+ {"Data": [["Code", "Status"], ["00123", "NA"]]},
+ )
+ sections = await ExcelParser().parse(xlsx_bytes, "demo.xlsx")
+
+ self.assertEqual(
+ [s.model_dump() for s in sections],
+ [
+ {
+ "content": {
+ "type": "text",
+ "text": (
+ "Sheet: Data\n"
+ "| Code | Status |\n"
+ "| --- | --- |\n"
+ "| 00123 | NA |\n"
+ ),
+ "id": AnyString(),
+ "created_at": AnyString(),
+ "finished_at": None,
+ },
+ "source": "demo.xlsx",
+ "metadata": {},
+ },
+ ],
+ )
+
async def test_multi_sheet_merged_by_default(self) -> None:
"""``separate_sheet=False`` (default) merges sheets into one
Section."""