@@ -686,13 +686,16 @@ def render(self, context: Context, line: str) -> None:
686686 def fetchdf (self , context : Context , line : str , sql : str ) -> None :
687687 """Fetches a dataframe from sql, optionally storing it in a variable."""
688688 args = parse_argstring (self .fetchdf , line )
689-
689+
690690 # Check if we're using Athena and use PandasCursor directly
691- if hasattr (context .engine_adapter , 'DIALECT' ) and context .engine_adapter .DIALECT == 'athena' :
691+ if (
692+ hasattr (context .engine_adapter , "DIALECT" )
693+ and context .engine_adapter .DIALECT == "athena"
694+ ):
692695 df = self ._fetchdf_athena_pandas_cursor (context , sql )
693696 else :
694697 df = context .fetchdf (sql )
695-
698+
696699 if args .df_var :
697700 self ._shell .user_ns [args .df_var ] = df
698701 self .display (df )
@@ -1200,22 +1203,23 @@ def destroy(self, context: Context, line: str) -> None:
12001203
12011204 def _fetchdf_athena_pandas_cursor (self , context : Context , sql : str ) -> pd .DataFrame :
12021205 """Special implementation for Athena using PandasCursor with SQLGlot transpilation"""
1203-
1206+
12041207 try :
12051208 from pyathena .pandas .cursor import PandasCursor
12061209 from pyathena import connect
12071210 except ImportError as e :
12081211 raise MagicError (f"PyAthena with pandas support is required: { e } " )
1209-
1212+
12101213 try :
12111214 conn_config = context .config .get_connection (context .config .default_connection )
12121215 connection_kwargs = {
1213- k : v for k , v in conn_config .dict ().items ()
1216+ k : v
1217+ for k , v in conn_config .dict ().items ()
12141218 if k in conn_config ._connection_kwargs_keys and v is not None
12151219 }
12161220 cursor = connect (cursor_class = PandasCursor , ** connection_kwargs ).cursor ()
12171221 return cursor .execute (sql ).as_pandas ()
1218-
1222+
12191223 except Exception as e :
12201224 # Fall back to the regular fetchdf method if PandasCursor fails
12211225 context .console .log_error (f"PandasCursor failed, falling back to standard method: { e } " )
0 commit comments