()
| 235 | * Clear Python namespace (keep imports) |
| 236 | */ |
| 237 | export async function clearPythonNamespace(): Promise<void> { |
| 238 | const pyodide = getPyodide(); |
| 239 | if (!pyodide) { |
| 240 | return; |
| 241 | } |
| 242 | |
| 243 | await pyodide.runPython(` |
| 244 | # Get list of user-defined variables |
| 245 | user_vars = [name for name in globals().keys() |
| 246 | if not name.startswith('_') |
| 247 | and name not in ['In', 'Out', 'exit', 'quit', 'get_plot_base64', 'df_to_dict'] |
| 248 | and not callable(globals()[name]) |
| 249 | and name not in ['np', 'pd', 'plt', 'matplotlib', 'numpy', 'pandas']] |
| 250 | |
| 251 | # Delete user variables |
| 252 | for var in user_vars: |
| 253 | try: |
| 254 | del globals()[var] |
| 255 | except: |
| 256 | pass |
| 257 | |
| 258 | # Clear matplotlib figures |
| 259 | import matplotlib.pyplot as plt |
| 260 | plt.close('all') |
| 261 | `); |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Format DataFrame for display |
no test coverage detected