Skip to content

Commit 16e98e3

Browse files
authored
fix: Update Python version mapping for Dataproc runtime 3.0 to Python 3.12 (#155)
1 parent 356d9b7 commit 16e98e3

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

google/cloud/dataproc_spark_connect/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ def _check_python_version_compatibility(self, runtime_version):
734734

735735
# Runtime version to server Python version mapping
736736
RUNTIME_PYTHON_MAP = {
737-
"3.0": (3, 11),
737+
"3.0": (3, 12),
738738
}
739739

740740
client_python = sys.version_info[:2] # (major, minor)

tests/unit/test_init.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,42 @@
2121
class TestPythonVersionCheck(unittest.TestCase):
2222

2323
def test_python_version_mismatch_warning_for_runtime_30(self):
24-
"""Test that warning is shown when client Python doesn't match runtime 3.0 (Python 3.11)"""
25-
with mock.patch("sys.version_info", (3, 12, 0)):
24+
"""Test that warning is shown when client Python doesn't match runtime 3.0 (Python 3.12)"""
25+
runtime_version = "3.0"
26+
server_py_major, server_py_minor = 3, 12
27+
client_py_major, client_py_minor = 3, 11
28+
29+
with mock.patch(
30+
"sys.version_info", (client_py_major, client_py_minor, 0)
31+
):
2632
with mock.patch("warnings.warn") as mock_warn:
2733
session_builder = DataprocSparkSession.Builder()
28-
session_builder._check_python_version_compatibility("3.0")
34+
session_builder._check_python_version_compatibility(
35+
runtime_version
36+
)
2937

3038
expected_warning = (
31-
"Python version mismatch detected: Client is using Python 3.12, "
32-
"but Dataproc runtime 3.0 uses Python 3.11. "
39+
f"Python version mismatch detected: Client is using Python {client_py_major}.{client_py_minor}, "
40+
f"but Dataproc runtime {runtime_version} uses Python {server_py_major}.{server_py_minor}. "
3341
"This mismatch may cause issues with Python UDF (User Defined Function) compatibility. "
34-
"Consider using Python 3.11 for optimal UDF execution."
42+
f"Consider using Python {server_py_major}.{server_py_minor} for optimal UDF execution."
3543
)
3644
mock_warn.assert_called_once_with(
3745
expected_warning, stacklevel=3
3846
)
3947

4048
def test_no_warning_when_python_versions_match_runtime_30(self):
41-
"""Test that no warning is shown when client Python matches runtime 3.0 (Python 3.11)"""
42-
with mock.patch("sys.version_info", (3, 11, 0)):
49+
"""Test that no warning is shown when client Python matches runtime 3.0 (Python 3.12)"""
50+
runtime_version = "3.0"
51+
client_py_major, client_py_minor = 3, 12
52+
with mock.patch(
53+
"sys.version_info", (client_py_major, client_py_minor, 0)
54+
):
4355
with mock.patch("warnings.warn") as mock_warn:
4456
session_builder = DataprocSparkSession.Builder()
45-
session_builder._check_python_version_compatibility("3.0")
57+
session_builder._check_python_version_compatibility(
58+
runtime_version
59+
)
4660

4761
mock_warn.assert_not_called()
4862

0 commit comments

Comments
 (0)