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

Function read_data_file

RealChart2Code_eval/evaluate_task2.py:197–222  ·  view source on GitHub ↗
(file_path: Path, max_rows: int = 10)

Source from the content-addressed store, hash-verified

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

Callers 1

prepare_task_infoFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected