Skip to content

Commit

Permalink
fix: fix code newline character issue introduced by astor.to_source (#…
Browse files Browse the repository at this point in the history
…345)

* use ast.unparse instead of astor.to_source()

* Revert to astor.to_source for unparsing and override pretty_source to avoid adding newline

* fix formatting
  • Loading branch information
redpin-pankaj authored Jul 8, 2023
1 parent 5e3f311 commit daf7336
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pandasai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def _clean_code(self, code: str) -> str:
new_body.append(node)

new_tree = ast.Module(body=new_body)
return astor.to_source(new_tree).strip()
return astor.to_source(new_tree, pretty_source=lambda x: "".join(x)).strip()

def _get_environment(self) -> dict:
"""
Expand Down
2 changes: 1 addition & 1 deletion pandasai/helpers/save_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ def add_save_chart(
logging.info(chart_save_msg)

new_tree = ast.Module(body=new_body)
return astor.to_source(new_tree).strip()
return astor.to_source(new_tree, pretty_source=lambda x: "".join(x)).strip()

0 comments on commit daf7336

Please sign in to comment.