Nipun Claude commited on
Commit
8673e7c
·
1 Parent(s): 7a86a16

Expand system prompt with comprehensive coding best practices

Browse files

Add 35+ generic coding rules covering:
- Data validation & safety (6 rules)
- Variable & type handling (6 rules)
- Pandas operations (6 rules)
- Matplotlib & plotting (6 rules)
- Error prevention (7 rules)

This provides LLM with broad toolkit for robust code generation across diverse scenarios.

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

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

Files changed (1) hide show
  1. src.py +40 -6
src.py CHANGED
@@ -311,12 +311,46 @@ SAFETY & ROBUSTNESS RULES:
311
  - Use proper string formatting for answers with units (μg/m³)
312
 
313
  CRITICAL CODING PRACTICES:
314
- - Always convert pandas/numpy objects to proper Python types before operations
315
- - Use descriptive variable names (avoid single letters in complex logic)
316
- - Ensure all variables are defined before use
317
- - Convert datetime/period objects to appropriate types (.astype(str), .astype(int))
318
- - Reference DataFrame properly in all column operations: df['column'] not 'column'
319
- - Use proper data type checking and conversion for all operations
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
320
 
321
  TECHNICAL REQUIREMENTS:
322
  - Save final result in variable called 'answer'
 
311
  - Use proper string formatting for answers with units (μg/m³)
312
 
313
  CRITICAL CODING PRACTICES:
314
+
315
+ DATA VALIDATION & SAFETY:
316
+ - Always check if DataFrames/Series are empty before operations: if df.empty: return
317
+ - Use .dropna() to handle missing values or .fillna() with appropriate defaults
318
+ - Validate column names exist before accessing: if 'column' in df.columns
319
+ - Check data types before operations: df['col'].dtype, isinstance() checks
320
+ - Handle edge cases: empty results, single row/column DataFrames, all NaN columns
321
+ - Use .copy() when modifying DataFrames to avoid SettingWithCopyWarning
322
+
323
+ VARIABLE & TYPE HANDLING:
324
+ - Use descriptive variable names (avoid single letters in complex operations)
325
+ - Ensure all variables are defined before use - initialize with defaults
326
+ - Convert pandas/numpy objects to proper Python types before operations
327
+ - Convert datetime/period objects appropriately: .astype(str), .dt.strftime(), int()
328
+ - Always cast to appropriate types for indexing: int(), str(), list()
329
+ - Use explicit type conversions rather than relying on implicit casting
330
+
331
+ PANDAS OPERATIONS:
332
+ - Reference DataFrame properly: df['column'] not 'column' in operations
333
+ - Use .loc/.iloc correctly for indexing - avoid chained indexing
334
+ - Use .reset_index() after groupby operations when needed for clean DataFrames
335
+ - Sort results for consistent output: .sort_values(), .sort_index()
336
+ - Use .round() for numerical results to avoid excessive decimals
337
+ - Chain operations carefully - split complex chains for readability
338
+
339
+ MATPLOTLIB & PLOTTING:
340
+ - Always call plt.close() after saving plots to prevent memory leaks
341
+ - Use descriptive titles, axis labels, and legends
342
+ - Handle cases where no data exists for plotting
343
+ - Use proper figure sizing: plt.figure(figsize=(width, height))
344
+ - Convert datetime indices to strings for plotting if needed
345
+ - Use color palettes consistently
346
+
347
+ ERROR PREVENTION:
348
+ - Use try-except blocks for operations that might fail
349
+ - Check denominators before division operations
350
+ - Validate array/list lengths before indexing
351
+ - Use .get() method for dictionary access with defaults
352
+ - Handle timezone-aware vs naive datetime objects consistently
353
+ - Use proper string formatting and encoding for text output
354
 
355
  TECHNICAL REQUIREMENTS:
356
  - Save final result in variable called 'answer'