Nipun Claude commited on
Commit
91be342
·
1 Parent(s): 7102d87

Add critical numpy indexing fixes to system prompt

Browse files

- Add dedicated section for NUMPY INDEXING FIXES with clear examples
- Emphasize ALWAYS converting pandas/numpy values to int before using as indices
- Provide specific example: calendar.month_name[int(month_value)]
- Add guidance for int() conversion in various scenarios: int(row['column']), int(max_idx)
- This should fix the recurring 'numpy.float64 cannot be used as index' errors
- Make the guidance more prominent and specific

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

Files changed (1) hide show
  1. src.py +6 -1
src.py CHANGED
@@ -306,11 +306,16 @@ SAFETY & ROBUSTNESS RULES:
306
  - Validate date ranges exist in data
307
  - Use proper string formatting for answers with units (μg/m³)
308
 
 
 
 
 
 
 
309
  TECHNICAL REQUIREMENTS:
310
  - Save final result in variable called 'answer'
311
  - For TEXT: Store the direct answer as a string in 'answer'
312
  - For PLOTS: Save with unique filename f"plot_{{uuid.uuid4().hex[:8]}}.png" and store filename in 'answer'
313
- - Convert numpy types to int when using as indices: int(value)
314
  - Always use .iloc or .loc properly for pandas indexing
315
  - Close matplotlib figures with plt.close() to prevent memory leaks
316
  - Use proper column name checks before accessing columns
 
306
  - Validate date ranges exist in data
307
  - Use proper string formatting for answers with units (μg/m³)
308
 
309
+ CRITICAL: NUMPY INDEXING FIXES:
310
+ - ALWAYS convert pandas/numpy values to int before using as list indices
311
+ - Example: calendar.month_name[int(month_value)] NOT calendar.month_name[month_value]
312
+ - Use int() conversion for ANY value used as index: int(row['month']), int(max_idx), etc.
313
+ - When accessing pandas iloc results, wrap in int(): int(df.loc[idx, 'column'])
314
+
315
  TECHNICAL REQUIREMENTS:
316
  - Save final result in variable called 'answer'
317
  - For TEXT: Store the direct answer as a string in 'answer'
318
  - For PLOTS: Save with unique filename f"plot_{{uuid.uuid4().hex[:8]}}.png" and store filename in 'answer'
 
319
  - Always use .iloc or .loc properly for pandas indexing
320
  - Close matplotlib figures with plt.close() to prevent memory leaks
321
  - Use proper column name checks before accessing columns