Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
laowantong committed Sep 15, 2024
1 parent 92bf8bd commit dfe6c66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/sql/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,23 +586,23 @@ def interactive_execute_wrapper(**kwargs):
and not isinstance(result, str)
and self.column_local_vars
):
# Instead of returning values, set variables directly in the
# users namespace. Variable names given by column names
# Set variables directly in the users namespace.
# Variable names given by column names

if self.autopandas or self.autopolars:
keys = result.keys()
self.shell.user_ns.update(result)
result = None
else:
keys = result.keys
result = result.dict()
self.shell.user_ns.update(result.dict())

if self.feedback:
display.message(
"Returning data to local variables [{}]".format(", ".join(keys))
)

self.shell.user_ns.update(result)

return None
return result
else:
if command.result_var:
self.shell.user_ns.update({command.result_var: result})
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def test_displaylimit_with_count_statement(ip, load_penguin, config_value):
def test_column_local_vars(ip):
ip.run_line_magic("config", "SqlMagic.column_local_vars = True")
result = runsql(ip, "SELECT * FROM author;")
assert result is None
assert result is not None
assert "William" in ip.user_global_ns["first_name"]
assert "Shakespeare" in ip.user_global_ns["last_name"]
assert len(ip.user_global_ns["first_name"]) == 2
Expand Down

0 comments on commit dfe6c66

Please sign in to comment.