@@ -62,47 +62,47 @@ def stackql(self, line, cell=None):
6262 elif not is_cell_magic :
6363 return results
6464
65- def _display_with_csv_download (self , df ):
66- """Display DataFrame with CSV download link.
67-
68- :param df: The DataFrame to display and make downloadable.
69- """
70- import IPython .display
71-
72- try :
73- # Generate CSV data
74- import io
75- import base64
76- csv_buffer = io .StringIO ()
77- df .to_csv (csv_buffer , index = False )
78- csv_data = csv_buffer .getvalue ()
79-
80- # Encode to base64 for data URI
81- csv_base64 = base64 .b64encode (csv_data .encode ()).decode ()
65+ def _display_with_csv_download (self , df ):
66+ """Display DataFrame with CSV download link.
8267
83- # Create download link
84- download_link = f'data:text/csv;base64,{ csv_base64 } '
85-
86- # Display the DataFrame first
87- IPython .display .display (df )
88-
89- # Create and display the download button
90- download_html = f'''
91- <div style="margin-top: 10px;">
92- <a href="{ download_link } " download="stackql_results.csv"
93- style="display: inline-block; padding: 8px 16px; background-color: #007cba;
94- color: white; text-decoration: none; border-radius: 4px;
95- font-family: Arial, sans-serif; font-size: 14px; border: none; cursor: pointer;">
96- 📥 Download CSV
97- </a>
98- </div>
99- '''
100- IPython .display .display (IPython .display .HTML (download_html ))
68+ :param df: The DataFrame to display and make downloadable.
69+ """
70+ import IPython .display
10171
102- except Exception as e :
103- # If CSV generation fails, just display the DataFrame normally
104- IPython .display .display (df )
105- print (f"Error generating CSV download: { e } " )
72+ try :
73+ # Generate CSV data
74+ import io
75+ import base64
76+ csv_buffer = io .StringIO ()
77+ df .to_csv (csv_buffer , index = False )
78+ csv_data = csv_buffer .getvalue ()
79+
80+ # Encode to base64 for data URI
81+ csv_base64 = base64 .b64encode (csv_data .encode ()).decode ()
82+
83+ # Create download link
84+ download_link = f'data:text/csv;base64,{ csv_base64 } '
85+
86+ # Display the DataFrame first
87+ IPython .display .display (df )
88+
89+ # Create and display the download button
90+ download_html = f'''
91+ <div style="margin-top: 10px;">
92+ <a href="{ download_link } " download="stackql_results.csv"
93+ style="display: inline-block; padding: 8px 16px; background-color: #007cba;
94+ color: white; text-decoration: none; border-radius: 4px;
95+ font-family: Arial, sans-serif; font-size: 14px; border: none; cursor: pointer;">
96+ 📥 Download CSV
97+ </a>
98+ </div>
99+ '''
100+ IPython .display .display (IPython .display .HTML (download_html ))
101+
102+ except Exception as e :
103+ # If CSV generation fails, just display the DataFrame normally
104+ IPython .display .display (df )
105+ print (f"Error generating CSV download: { e } " )
106106
107107def load_ipython_extension (ipython ):
108108 """Load the non-server magic in IPython.
0 commit comments