Skip to content

Commit

Permalink
Adjusment for displayHTML (#19)
Browse files Browse the repository at this point in the history
* fixing issue with bround

* adjustment for displayHTML

* typo
  • Loading branch information
orellabac authored Jan 26, 2023
1 parent 060655e commit 3b90836
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
7 changes: 6 additions & 1 deletion CHANGE_LOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,9 @@ from_env modified to only set connection settings if the variable has a value

Version 0.0.17
--------------
Fixing issue with bround
Fixing issue with bround


Version 0.0.18
--------------
Fixing issues when getting displayHTML on some environments
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ and then use that as a normal dataframe:
if tables.count() > 5:
print("There are more that 5 tables")
```
If you dont specify a name you can still access the last result using `__df`.

The standard IPython display does not render snowpark `dataframe`. You can use `df.show()` but by default something like: `display(df)` will just print: `<snowflake.snowpark.dataframe.DataFrame at 0x7fa67d099c40>`

Expand All @@ -417,6 +418,4 @@ There is an small script that uploads your notebook to snowflake into an stage a
To use it:

- install snowpark_extensions
- runner --notebook notebook1.ipynb --stage my_stage --package ""


- runner --notebook notebook1.ipynb --stage my_stage --package ""
15 changes: 13 additions & 2 deletions snowpark_extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
from .column_extensions import *
from .utils import display


def get_display_html() -> None:
import inspect
for frame in inspect.getouterframes(inspect.currentframe()):
global_names = set(frame.frame.f_globals)
# Use multiple functions to reduce risk of mismatch
if all(v in global_names for v in ["displayHTML", "display", "spark"]):
return frame.frame.f_globals["displayHTML"]
raise Exception("Unable to detect displayHTML function")

def load_ipython_extension(ipython):
def instructions():
inst = """
Expand All @@ -21,7 +31,8 @@ def instructions():
error_message_template="""<div style="background-color: #f44336; color: white; padding: 16px;"><strong>Error:</strong> <span id="error-message">@error</span></div>"""
output_cell_output = None
try:
output_cell_output = displayHTML
output_cell_output = get_display_html()
print("displayHTML detected")
except:
from IPython.display import display, HTML
output_cell_output = lambda x: display(HTML(x))
Expand All @@ -48,7 +59,7 @@ def sql(self, line, cell):
if name:
self.shell.user_ns[name] = df
else:
self.shell.user_ns["$df"] = df
self.shell.user_ns["__df"] = df
except SnowparkSQLException as sce:
error_msg = sce.message
formatted = error_message_template.replace("@error", error_msg)
Expand Down

0 comments on commit 3b90836

Please sign in to comment.