Skip to content

Commit 7f56692

Browse files
DLT runtimes display fix and issue #182 (#186)
* Bug fix for display in DLT runtimes * #182 * addressing the Tristan's comments. * addressing the describe failure comment * correcting the import statement in the init.py * correcting the name of the column for issue #182 in both the scala and the python code * adding the IPython NoneType handler condition * changed the name to snake case * streamling by removing ipython and namespace checks
1 parent 30e71eb commit 7f56692

File tree

6 files changed

+13
-14
lines changed

6 files changed

+13
-14
lines changed

python/tempo/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from tempo.tsdf import TSDF
2-
from tempo.utils import display
2+
from tempo.utils import display

python/tempo/tsdf.py

+1
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ def describe(self):
324324
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])
325325

326326
full_smry = global_smry_rec.union(desc_stats)
327+
full_smry = full_smry.withColumnRenamed("unique_ts_count","unique_time_series_count")
327328

328329
try:
329330
dbutils.fs.ls("/")

python/tempo/utils.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
logger = logging.getLogger(__name__)
1111
PLATFORM = "DATABRICKS" if "DB_HOME" in os.environ.keys() else "NON_DATABRICKS"
12+
1213
"""
1314
DB_HOME env variable has been chosen and that's because this variable is a special variable that will be available in DBR.
1415
1516
This constant is to ensure the correct behaviour of the show and display methods are called based on the platform
1617
where the code is running from.
1718
"""
1819

19-
20-
def __isnotebookenv():
20+
def __is_capable_of_html_rendering():
2121
"""
2222
This method returns a boolean value signifying whether the environment is a notebook environment
2323
capable of rendering HTML or not.
@@ -54,31 +54,28 @@ def display_unavailable(df):
5454
logger.error("'display' method not available in this environment. Use 'show' method instead.")
5555

5656

57-
ENV_BOOLEAN = __isnotebookenv()
58-
59-
if PLATFORM == "DATABRICKS":
60-
method = get_ipython().user_ns['display']
57+
ENV_BOOLEAN = __is_capable_of_html_rendering()
6158

6259

60+
if (PLATFORM == "DATABRICKS") and (type(get_ipython()) != type(None)) and ('display' in get_ipython().user_ns.keys()):
61+
method = get_ipython().user_ns['display']
6362
# Under 'display' key in user_ns the original databricks display method is present
6463
# to know more refer: /databricks/python_shell/scripts/db_ipykernel_launcher.py
6564
def display_improvised(obj):
6665
if type(obj).__name__ == 'TSDF':
6766
method(obj.df)
6867
else:
6968
method(obj)
70-
71-
7269
display = display_improvised
73-
elif __isnotebookenv():
70+
71+
elif ENV_BOOLEAN:
7472
def display_html_improvised(obj):
7573
if type(obj).__name__ == 'TSDF':
7674
display_html(obj.df)
7775
else:
7876
display_html(obj)
79-
80-
8177
display = display_html_improvised
78+
8279
else:
8380
display = display_unavailable
8481

python/tests/tsdf_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def test_describe(self):
156156
# joined dataframe should equal the expected dataframe
157157
# self.assertDataFramesEqual(res, dfExpected)
158158
assert res.count() == 7
159-
assert res.filter(F.col("unique_ts_count") != " ").select(F.max(F.col('unique_ts_count'))).collect()[0][
159+
assert res.filter(F.col("unique_time_series_count") != " ").select(F.max(F.col('unique_time_series_count'))).collect()[0][
160160
0] == "1"
161161
assert res.filter(F.col("min_ts") != " ").select(F.col('min_ts').cast("string")).collect()[0][
162162
0] == '2020-08-01 00:00:10'

scala/tempo/src/main/scala/com/databrickslabs/tempo/TSDF.scala

+1
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ private[tempo] sealed class BaseTSDF(val df: DataFrame,
453453
val global_smry_rec = desc_stats.limit(1).select(non_summary_cols_blank: _*)
454454

455455
val full_smry = global_smry_rec.union(desc_stats)
456+
val full_smry = full_smry.withColumnRenamed("unique_ts_count","unique_time_series_count")
456457

457458
return(full_smry)
458459
}

scala/tempo/src/test/scala/com/databrickslabs/tempo/DescribeTests.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class DescribeTests
4242
// joined dataframe should equal the expected dataframe
4343
// self.assertDataFramesEqual(res, dfExpected)
4444
assert(res.count == 7)
45-
assert(res.select(max(col("unique_ts_count"))).collect()(0)(0) == "1")
45+
assert(res.select(max(col("unique_time_series_count"))).collect()(0)(0) == "1")
4646
assert(res.select(col("min_ts").cast("string")).collect()(0)(0) == "2020-08-01 00:00:10")
4747
assert(res.select(col("max_ts").cast("string")).collect()(0)(0) == "2020-09-01 00:19:12")
4848
}

0 commit comments

Comments
 (0)