Skip to content

Commit

Permalink
Flat formatting of the df_markdown #20
Browse files Browse the repository at this point in the history
  • Loading branch information
paultiq committed Feb 14, 2024
1 parent 23818b1 commit 4159b45
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
7 changes: 3 additions & 4 deletions magic_duckdb/duckdb_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import json
from magic_duckdb.extras.explain_analyze_graphviz import draw_graphviz
from magic_duckdb.extras.ast_graphviz import ast_draw_graphviz, ast_tree
from IPython.display import Markdown


def execute_db(
Expand Down Expand Up @@ -139,14 +138,14 @@ def execute(
raise ValueError(f"Error executing {query_string} in DuckDB") from e

if r is None or ("relation" == export_function):
return r, None
return r
else:
if export_function == "df_markdown":
md = r.df().to_markdown(index=False)
return md, Markdown(md)
return md

else:
export_function = export_function
f = getattr(r, export_function)

return f(**export_kwargs), None
return f(**export_kwargs)
8 changes: 3 additions & 5 deletions magic_duckdb/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def execute(self, line: str = "", cell: str = "", local_ns=None):
if args.tables:
return thisconnection.get_table_names(query)

o, display_o = dbwrapper.execute(
o = dbwrapper.execute(
query_string=query,
connection=thisconnection,
export_function=args.type[0]
Expand All @@ -249,10 +249,8 @@ def execute(self, line: str = "", cell: str = "", local_ns=None):
if args.output:
user_ns[args.output[0]] = o

if display_o is not None:
return display_o
else:
return o

return o

except ConnectionException as e:
logger.exception(
Expand Down
3 changes: 2 additions & 1 deletion notebooks/format_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"# df_markdown in a line magic\n",
"\n",
"a = %dql -t df_markdown select 'asdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasd', 'asdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasd', 'asdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasd', null as nullvalue, * from range(10)\n",
"a.data"
"\n",
"a"
]
}
],
Expand Down

0 comments on commit 4159b45

Please sign in to comment.