Skip to content

Commit c62fe05

Browse files
committed
Inner dev loop fixes
1 parent dc7b2e6 commit c62fe05

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

default_python/requirements-dev.txt

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
## pytest is the default package used for testing
77
pytest
88

9+
## Add code completion support for DLT
10+
databricks-dlt
11+
912
## databricks-connect can be used to run parts of this project locally.
1013
## See https://docs.databricks.com/dev-tools/databricks-connect.html.
1114
##
+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from pyspark.sql import SparkSession
22

3-
def get_taxis():
4-
spark = SparkSession.builder.getOrCreate()
3+
def get_taxis(spark: SparkSession):
54
return spark.read.table("samples.nyctaxi.trips")
65

76
def main():
8-
get_taxis().show(5)
7+
get_taxis(spark).show(5)
98

109
if __name__ == '__main__':
1110
main()

default_python/src/notebook.ipynb

+21-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@
1919
},
2020
{
2121
"cell_type": "code",
22-
"execution_count": 0,
22+
"execution_count": null,
23+
"metadata": {},
24+
"outputs": [],
25+
"source": [
26+
"%load_ext autoreload\n",
27+
"%autoreload 2"
28+
]
29+
},
30+
{
31+
"cell_type": "code",
32+
"execution_count": null,
2333
"metadata": {
2434
"application/vnd.databricks.v1+cell": {
2535
"cellMetadata": {
@@ -36,7 +46,7 @@
3646
"source": [
3747
"from default_python import main\n",
3848
"\n",
39-
"main.get_taxis().show(10)"
49+
"main.get_taxis(spark).show(10)"
4050
]
4151
}
4252
],
@@ -56,8 +66,16 @@
5666
"name": "python3"
5767
},
5868
"language_info": {
69+
"codemirror_mode": {
70+
"name": "ipython",
71+
"version": 3
72+
},
73+
"file_extension": ".py",
74+
"mimetype": "text/x-python",
5975
"name": "python",
60-
"version": "3.11.4"
76+
"nbconvert_exporter": "python",
77+
"pygments_lexer": "ipython3",
78+
"version": "3.11.6"
6179
}
6280
},
6381
"nbformat": 4,

default_python/tests/main_test.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
from databricks.connect import DatabricksSession
2-
from pyspark.sql import SparkSession
1+
from databricks.connect import DatabricksSession as SparkSession
32
from default_python import main
3+
from pytest import fixture
44

55
# Create a new Databricks Connect session. If this fails,
66
# check that you have configured Databricks Connect correctly.
77
# See https://docs.databricks.com/dev-tools/databricks-connect.html.
88

9-
SparkSession.builder = DatabricksSession.builder
10-
SparkSession.builder.getOrCreate()
9+
@fixture(scope="session")
10+
def spark():
11+
return SparkSession.builder.getOrCreate()
1112

12-
def test_main():
13-
taxis = main.get_taxis()
13+
def test_main(spark):
14+
taxis = main.get_taxis(spark)
1415
assert taxis.count() > 5

0 commit comments

Comments
 (0)