Files
AIclinicalresearch/extraction_service/test_module.py
HaHafeng 75ceeb0653 hotfix(dc/tool-c): Fix compute formula validation and binning NaN serialization
Critical fixes:
1. Compute column: Add Chinese comma support in formula validation
   - Problem: Formula with Chinese comma failed validation
   - Fix: Add Chinese comma character to allowed_chars regex
   - Example: Support formulas like 'col1(kg)+ col2,col3'

2. Binning operation: Fix NaN serialization error
   - Problem: 'Out of range float values are not JSON compliant: nan'
   - Fix: Enhanced NaN/inf handling in binning endpoint
   - Added np.inf/-np.inf replacement before JSON serialization
   - Added manual JSON serialization with NaN->null conversion

3. Enhanced all operation endpoints for consistency
   - Updated conditional, dropna endpoints with same NaN/inf handling
   - Ensures all operations return JSON-compliant data

Modified files:
- extraction_service/operations/compute.py: Add Chinese comma to regex
- extraction_service/main.py: Enhanced NaN handling in binning/conditional/dropna

Status: Hotfix complete, ready for testing
2025-12-09 08:45:27 +08:00

32 lines
856 B
Python

"""测试dc_executor模块"""
print("测试dc_executor模块导入...")
try:
from services.dc_executor import validate_code, execute_pandas_code
print("✅ 模块导入成功")
# 测试验证功能
print("\n测试validate_code...")
result = validate_code("df['x'] = 1")
print(f"✅ validate_code成功: {result}")
# 测试执行功能
print("\n测试execute_pandas_code...")
test_data = [{"age": 25}, {"age": 65}]
result = execute_pandas_code(test_data, "df['old'] = df['age'] > 60")
print(f"✅ execute_pandas_code成功: success={result['success']}")
if result['success']:
print(f" 结果: {result['result_data']}")
print("\n🎉 所有模块测试通过!")
except Exception as e:
print(f"❌ 测试失败: {e}")
import traceback
traceback.print_exc()