Skip to content

DLT runtimes display fix and issue #182 #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 8, 2022
14 changes: 13 additions & 1 deletion python/tempo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
from IPython import get_ipython

from tempo.tsdf import TSDF
from tempo.utils import display
if (
('create_dlt_table_fn' not in list(get_ipython().user_ns.keys()))
and
('dlt_sql_fn' not in list(get_ipython().user_ns.keys()))
):
from tempo.utils import display

'''
Conditonal import of display so that it doesn't gets imported in runtimes where display is not required.
For example in DATABRICKS Delta Live Tables Runtimes.
'''
4 changes: 2 additions & 2 deletions python/tempo/tsdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@ def describe(self):
non_summary_cols = [c for c in desc_stats.columns if c != 'summary']


desc_stats = desc_stats.select(f.col("summary"), f.lit(" ").alias("unique_ts_count"), f.lit(" ").alias("min_ts"),
desc_stats = desc_stats.select(f.col("summary"), f.lit(" ").alias("unique_time_series_count"), f.lit(" ").alias("min_ts"),
f.lit(" ").alias("max_ts"), f.lit(" ").alias("granularity"), *non_summary_cols)

# add in single record with global summary attributes and the previously computed missing value and Spark data frame describe stats
global_smry_rec = desc_stats.limit(1).select(f.lit('global').alias("summary"),f.lit(unique_ts).alias("unique_ts_count"), f.lit(min_ts).alias("min_ts"), f.lit(max_ts).alias("max_ts"), f.lit(gran).alias("granularity"), *[f.lit(" ").alias(c) for c in non_summary_cols])
global_smry_rec = desc_stats.limit(1).select(f.lit('global').alias("summary"),f.lit(unique_ts).alias("unique_time_series_count"), f.lit(min_ts).alias("min_ts"), f.lit(max_ts).alias("max_ts"), f.lit(gran).alias("granularity"), *[f.lit(" ").alias(c) for c in non_summary_cols])

full_smry = global_smry_rec.union(desc_stats)

Expand Down
34 changes: 22 additions & 12 deletions python/tempo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,29 @@ def display_unavailable(df):
ENV_BOOLEAN = __isnotebookenv()

if PLATFORM == "DATABRICKS":
method = get_ipython().user_ns['display']


# Under 'display' key in user_ns the original databricks display method is present
# to know more refer: /databricks/python_shell/scripts/db_ipykernel_launcher.py
def display_improvised(obj):
if type(obj).__name__ == 'TSDF':
method(obj.df)
else:
method(obj)


display = display_improvised
# This below check is for ensuring compatibility with Databricks DLT runtimes
# This if logic ensures that the custom user's namespace of DLT runtimes
# which doesn't have PythonShell's Display object in the namespace doesn't result in an error.
if (
('create_dlt_table_fn' not in list(get_ipython().user_ns.keys()))
and
('dlt_sql_fn' not in list(get_ipython().user_ns.keys()))
):
method = get_ipython().user_ns['display']

# Under 'display' key in user_ns the original databricks display method is present
# to know more refer: /databricks/python_shell/scripts/db_ipykernel_launcher.py
def display_improvised(obj):
if type(obj).__name__ == 'TSDF':
method(obj.df)
else:
method(obj)


display = display_improvised
else:
display = display_unavailable
elif __isnotebookenv():
def display_html_improvised(obj):
if type(obj).__name__ == 'TSDF':
Expand Down