Skip to content

Commit 158243b

Browse files
deps: Updates deprecation warning to FutureWarning re: 3.7 and 3.8 (#338)
* deps: Updates deprecation warning to FutureWarning re: 3.7 and 3.8 * Changes pytest flag to ignore FutureWarning re: 3.7 and 3.8 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Changes pytest flag to ignore FutureWarning re: 3.7 and 3.8 --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent d8046c0 commit 158243b

File tree

3 files changed

+103
-12
lines changed

3 files changed

+103
-12
lines changed

db_dtypes/__init__.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -347,16 +347,22 @@ def __sub__(self, other):
347347
return super().__sub__(other)
348348

349349

350-
sys_major, sys_minor, sys_micro = _versions_helpers.extract_runtime_version()
351-
if sys_major == 3 and sys_minor in (7, 8):
352-
warnings.warn(
353-
"The python-bigquery library will stop supporting Python 3.7 "
354-
"and Python 3.8 in a future major release expected in Q4 2024. "
355-
f"Your Python version is {sys_major}.{sys_minor}.{sys_micro}. We "
356-
"recommend that you update soon to ensure ongoing support. For "
357-
"more details, see: [Google Cloud Client Libraries Supported Python Versions policy](https://cloud.google.com/python/docs/supported-python-versions)",
358-
PendingDeprecationWarning,
359-
)
350+
def _check_python_version():
351+
"""Checks the runtime Python version and issues a warning if needed."""
352+
sys_major, sys_minor, sys_micro = _versions_helpers.extract_runtime_version()
353+
if sys_major == 3 and sys_minor in (7, 8):
354+
warnings.warn(
355+
"The python-bigquery library as well as the python-db-dtypes-pandas library no "
356+
"longer supports Python 3.7 and Python 3.8. "
357+
f"Your Python version is {sys_major}.{sys_minor}.{sys_micro}. We "
358+
"recommend that you update soon to ensure ongoing support. For "
359+
"more details, see: [Google Cloud Client Libraries Supported Python Versions policy](https://cloud.google.com/python/docs/supported-python-versions)",
360+
FutureWarning,
361+
stacklevel=2, # Point warning to the caller of __init__
362+
)
363+
364+
365+
_check_python_version()
360366

361367

362368
if not JSONArray or not JSONDtype:

noxfile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def default(session, tests_path):
187187
session.run(
188188
"py.test",
189189
"--quiet",
190-
"-W default::PendingDeprecationWarning",
190+
"-W default::FutureWarning",
191191
f"--junitxml={os.path.split(tests_path)[-1]}_{session.python}_sponge_log.xml",
192192
"--cov=db_dtypes",
193193
"--cov=tests/unit",
@@ -265,7 +265,7 @@ def prerelease(session, tests_path):
265265
session.run(
266266
"py.test",
267267
"--quiet",
268-
"-W default::PendingDeprecationWarning",
268+
"-W default::FutureWarning",
269269
f"--junitxml={os.path.split(tests_path)[-1]}_prerelease_{session.python}_sponge_log.xml",
270270
"--cov=db_dtypes",
271271
"--cov=tests/unit",

tests/unit/test__init__.py

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from unittest import mock
16+
17+
import pytest
18+
19+
# Module paths used for mocking
20+
MODULE_PATH = "db_dtypes"
21+
HELPER_MODULE_PATH = f"{MODULE_PATH}._versions_helpers"
22+
MOCK_EXTRACT_VERSION = f"{HELPER_MODULE_PATH}.extract_runtime_version"
23+
MOCK_WARN = "warnings.warn" # Target the standard warnings module
24+
25+
26+
@pytest.mark.parametrize(
27+
"mock_version_tuple, version_str",
28+
[
29+
((3, 7, 10), "3.7.10"),
30+
((3, 7, 0), "3.7.0"),
31+
((3, 8, 5), "3.8.5"),
32+
((3, 8, 12), "3.8.12"),
33+
],
34+
)
35+
def test_check_python_version_warns_on_unsupported(mock_version_tuple, version_str):
36+
"""
37+
Test that _check_python_version issues a FutureWarning for Python 3.7/3.8.
38+
"""
39+
40+
from db_dtypes import _check_python_version
41+
42+
# Mock the helper function it calls and the warnings.warn function
43+
with mock.patch(MOCK_EXTRACT_VERSION, return_value=mock_version_tuple), mock.patch(
44+
MOCK_WARN
45+
) as mock_warn_call:
46+
_check_python_version() # Call the function
47+
48+
# Assert that warnings.warn was called exactly once
49+
mock_warn_call.assert_called_once()
50+
51+
# Check the arguments passed to warnings.warn
52+
args, kwargs = mock_warn_call.call_args
53+
assert len(args) >= 1 # Should have at least the message
54+
warning_message = args[0]
55+
warning_category = args[1] if len(args) > 1 else kwargs.get("category")
56+
57+
# Verify message content and category
58+
assert "longer supports Python 3.7 and Python 3.8" in warning_message
59+
assert warning_category == FutureWarning
60+
61+
62+
@pytest.mark.parametrize(
63+
"mock_version_tuple",
64+
[
65+
(3, 9, 1),
66+
(3, 10, 0),
67+
(3, 11, 2),
68+
(3, 12, 0),
69+
],
70+
)
71+
def test_check_python_version_does_not_warn_on_supported(mock_version_tuple):
72+
"""
73+
Test that _check_python_version does NOT issue a warning for other versions.
74+
"""
75+
76+
from db_dtypes import _check_python_version
77+
78+
# Mock the helper function it calls and the warnings.warn function
79+
with mock.patch(MOCK_EXTRACT_VERSION, return_value=mock_version_tuple), mock.patch(
80+
MOCK_WARN
81+
) as mock_warn_call:
82+
_check_python_version()
83+
84+
# Assert that warnings.warn was NOT called
85+
mock_warn_call.assert_not_called()

0 commit comments

Comments
 (0)