Skip to content

Commit 404f447

Browse files
error for old polars version
1 parent 6a2ae4c commit 404f447

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

bigframes/_config/bigquery_options.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import google.auth.credentials
2323
import requests.adapters
2424

25+
import bigframes._importing
2526
import bigframes.enums
2627
import bigframes.exceptions as bfe
2728

@@ -114,6 +115,8 @@ def __init__(
114115
client_endpoints_override = {}
115116

116117
self._client_endpoints_override = client_endpoints_override
118+
if enable_polars_execution:
119+
bigframes._importing.import_polars()
117120
self._enable_polars_execution = enable_polars_execution
118121

119122
@property
@@ -439,4 +442,5 @@ def enable_polars_execution(self, value: bool):
439442
"Polars execution is an experimental feature, and may not be stable. Must have polars installed."
440443
)
441444
warnings.warn(msg, category=bfe.PreviewWarning)
445+
bigframes._importing.import_polars()
442446
self._enable_polars_execution = value

bigframes/_importing.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
import importlib
15+
from types import ModuleType
16+
17+
from packaging import version
18+
19+
# Keep this in sync with setup.py
20+
POLARS_MIN_VERSION = version.Version("1.7.0")
21+
22+
23+
def import_polars() -> ModuleType:
24+
polars_module = importlib.import_module("polars")
25+
imported_version = version.Version(polars_module.build_info()["version"])
26+
if imported_version < POLARS_MIN_VERSION:
27+
raise ImportError(
28+
f"Imported polars version: {imported_version} is below the minimum version: {POLARS_MIN_VERSION}"
29+
)
30+
return polars_module

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
SYSTEM_TEST_EXTRAS: List[str] = []
108108
SYSTEM_TEST_EXTRAS_BY_PYTHON: Dict[str, List[str]] = {
109109
"3.9": ["tests"],
110-
"3.10": ["tests"],
110+
"3.10": ["tests", "polars"],
111111
"3.12": ["tests", "scikit-learn", "polars"],
112112
"3.13": ["tests", "polars"],
113113
}

testing/constraints-3.10.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ matplotlib==3.7.1
1515
psutil==5.9.5
1616
seaborn==0.13.1
1717
traitlets==5.7.1
18+
polars==1.7.0

0 commit comments

Comments
 (0)