MCPcopy Create free account
hub / github.com/Speakn0w/RealChart2Code / read_data_file

Function read_data_file

RealChart2Code_eval/evaluate_task3.py:204–229  ·  view source on GitHub ↗
(file_path: Path, max_rows: int = 10)

Source from the content-addressed store, hash-verified

202
203
204def read_data_file(file_path: Path, max_rows: int = 10) -> str:
205
206 try:
207 if file_path.suffix.lower() == '.csv':
208 df = pd.read_csv(file_path)
209 elif file_path.suffix.lower() == '.xlsx':
210 df = pd.read_excel(file_path)
211 else:
212 return f"Unsupported file format: {file_path.suffix}"
213
214 info = f"Dataset: {file_path.name}\n"
215 info += f"Shape: {df.shape}\n"
216 info += f"Columns: {list(df.columns)}\n\n"
217
218 info += "Data types:\n"
219 for col, dtype in df.dtypes.items():
220 info += f" {col}: {dtype}\n"
221 info += "\n"
222
223 info += f"First {min(max_rows, len(df))} rows:\n"
224 info += df.head(max_rows).to_string(index=False)
225
226 return info
227
228 except Exception as e:
229 return f"Error reading {file_path.name}: {str(e)}"
230
231
232def create_user_prompt(category: str, instruction: str, data_info: Dict[str, str]) -> str:

Callers 1

prepare_task_infoFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected