Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 00e0750

Browse files
sycaigcf-owl-bot[bot]
andauthoredMar 12, 2025
feat: warn when the BigFrames version is more than a year old (#1455)
* feat: warn when the version is beyond support period * move release date check to session init * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 742494c commit 00e0750

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed
 

‎bigframes/exceptions.py

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ class BadIndexerKeyWarning(Warning):
9191
"""The indexer key is not used correctly."""
9292

9393

94+
class ObsoleteVersionWarning(Warning):
95+
"""The BigFrames version is too old."""
96+
97+
9498
class ColorFormatter:
9599
WARNING = "\033[93m"
96100
ENDC = "\033[0m"

‎bigframes/session/__init__.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from __future__ import annotations
1818

19+
import datetime
1920
import logging
2021
import os
2122
import secrets
@@ -54,6 +55,8 @@
5455
)
5556
import pyarrow as pa
5657

58+
from bigframes import exceptions as bfe
59+
from bigframes import version
5760
import bigframes._config.bigquery_options as bigquery_options
5861
import bigframes.clients
5962
import bigframes.core.blocks as blocks
@@ -65,8 +68,6 @@
6568
# to register new and replacement ops with the Ibis BigQuery backend.
6669
import bigframes.dataframe
6770
import bigframes.dtypes
68-
import bigframes.exceptions
69-
import bigframes.exceptions as bfe
7071
import bigframes.functions._function_session as bff_session
7172
import bigframes.functions.function as bff
7273
import bigframes.session._io.bigquery as bf_io_bigquery
@@ -77,7 +78,6 @@
7778
import bigframes.session.planner
7879
import bigframes.session.temp_storage
7980
import bigframes.session.validation
80-
import bigframes.version
8181

8282
# Avoid circular imports.
8383
if typing.TYPE_CHECKING:
@@ -147,6 +147,8 @@ def __init__(
147147
context: Optional[bigquery_options.BigQueryOptions] = None,
148148
clients_provider: Optional[bigframes.session.clients.ClientsProvider] = None,
149149
):
150+
_warn_if_bf_version_is_obsolete()
151+
150152
if context is None:
151153
context = bigquery_options.BigQueryOptions()
152154

@@ -1813,3 +1815,11 @@ def read_gbq_object_table(
18131815

18141816
def connect(context: Optional[bigquery_options.BigQueryOptions] = None) -> Session:
18151817
return Session(context)
1818+
1819+
1820+
def _warn_if_bf_version_is_obsolete():
1821+
today = datetime.datetime.today()
1822+
release_date = datetime.datetime.strptime(version.__release_date__, "%Y-%m-%d")
1823+
if today - release_date > datetime.timedelta(days=365):
1824+
msg = f"Your BigFrames version {version.__version__} is more than 1 year old. Please update to the lastest version."
1825+
warnings.warn(msg, bfe.ObsoleteVersionWarning)

‎tests/unit/session/test_session.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
import pytest
2626

2727
import bigframes
28+
from bigframes import version
2829
import bigframes.enums
2930
import bigframes.exceptions
30-
31-
from .. import resources
31+
from tests.unit import resources
3232

3333
TABLE_REFERENCE = {
3434
"projectId": "my-project",
@@ -443,3 +443,18 @@ def test_session_init_fails_with_no_project():
443443
credentials=mock.Mock(spec=google.auth.credentials.Credentials)
444444
)
445445
)
446+
447+
448+
def test_session_init_warns_if_bf_version_is_too_old(monkeypatch):
449+
release_date = datetime.datetime.strptime(version.__release_date__, "%Y-%m-%d")
450+
current_date = release_date + datetime.timedelta(days=366)
451+
452+
class FakeDatetime(datetime.datetime):
453+
@classmethod
454+
def today(cls):
455+
return current_date
456+
457+
monkeypatch.setattr(datetime, "datetime", FakeDatetime)
458+
459+
with pytest.warns(bigframes.exceptions.ObsoleteVersionWarning):
460+
resources.create_bigquery_session()

0 commit comments

Comments
 (0)
Failed to load comments.