| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 32d9f7e commit dbaf8f5
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -78,8 +78,10 @@ | |||
| 78 | 78 | the variable name (ex. ``$my_dict_var``). See ``In[6]`` and ``In[7]`` | |
| 79 | 79 | in the Examples section below. | |
| 80 | 80 | * ``--engine <engine>`` (Optional[line argument]): | |
| 81 | - Set the execution engine, either 'pandas' (default) or 'bigframes' | ||
| 82 | - (experimental). | ||
| 81 | + [Deprecated] Set the execution engine, either 'pandas' (default) or | ||
| 82 | + 'bigframes'. | ||
| 83 | + Please use ``%load_ext bigframes`` and the ``%%bqsql`` magic instead. | ||
| 84 | + See: https://dataframes.bigquery.dev/notebooks/getting_started/magics.html | ||
| 83 | 85 | * ``--pyformat`` (Optional[line argument]): | |
| 84 | 86 | Warning! Do not use with user-provided values. | |
| 85 | 87 | This doesn't escape values. Use --params instead for proper SQL escaping. | |
@@ -397,8 +399,10 @@ def _create_dataset_if_necessary(client, dataset_id): | |||
| 397 | 399 | type=str, | |
| 398 | 400 | default=None, | |
| 399 | 401 | help=( | |
| 400 | - "Set the execution engine, either 'pandas' or 'bigframes'." | ||
| 401 | - "Defaults to engine set in the query setting in console." | ||
| 402 | + "[Deprecated] Set the execution engine, either 'pandas' or 'bigframes'. " | ||
| 403 | + "Defaults to engine set in the query setting in console. " | ||
| 404 | + "Please use %%load_ext bigframes and the %%%%bqsql magic instead. " | ||
| 405 | + "See: https://dataframes.bigquery.dev/notebooks/getting_started/magics.html" | ||
| 402 | 406 | ), | |
| 403 | 407 | ) | |
| 404 | 408 | @magic_arguments.argument( | |
@@ -510,6 +514,13 @@ def _split_args_line(line: str) -> Tuple[str, str]: | |||
| 510 | 514 | ||
| 511 | 515 | ||
| 512 | 516 | def _query_with_bigframes(query: str, params: List[Any], args: Any): | |
| 517 | + warnings.warn( | ||
| 518 | + "The bigframes engine is deprecated. Please use %load_ext bigframes " | ||
| 519 | + "and the %%bqsql magic instead. " | ||
| 520 | + "See: https://dataframes.bigquery.dev/notebooks/getting_started/magics.html", | ||
| 521 | + FutureWarning, | ||
| 522 | + stacklevel=2, | ||
| 523 | + ) | ||
| 513 | 524 | if args.dry_run: | |
| 514 | 525 | raise ValueError("Dry run is not supported by bigframes engine.") | |
| 515 | 526 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | 15 | from dataclasses import dataclass | |
| 16 | 16 | from typing import Optional | |
| 17 | + import warnings | ||
| 17 | 18 | ||
| 18 | 19 | import google.api_core.client_options as client_options | |
| 19 | 20 | import google.cloud.bigquery as bigquery | |
@@ -183,10 +184,15 @@ def project(self, value): | |||
| 183 | 184 | ||
| 184 | 185 | @property | |
| 185 | 186 | def engine(self) -> str: | |
| 186 | - """Engine to run the query. Could either be "pandas" or "bigframes". | ||
| 187 | + """[Deprecated] Engine to run the query. Could either be "pandas" or | ||
| 188 | + "bigframes". | ||
| 187 | 189 | ||
| 188 | 190 | If using "pandas", the query result will be stored in a Pandas dataframe. | |
| 189 | - If using "bigframes", the query result will be stored in a bigframes dataframe instead. | ||
| 191 | + If using "bigframes", the query result will be stored in a bigframes | ||
| 192 | + dataframe instead. | ||
| 193 | + | ||
| 194 | + Please use ``%load_ext bigframes`` and the ``%%bqsql`` magic instead. | ||
| 195 | + See: https://dataframes.bigquery.dev/notebooks/getting_started/magics.html | ||
| 190 | 196 | ||
| 191 | 197 | Example: | |
| 192 | 198 | Manully setting the content engine: | |
@@ -200,6 +206,14 @@ def engine(self) -> str: | |||
| 200 | 206 | def engine(self, value): | |
| 201 | 207 | if value != "pandas" and value != "bigframes": | |
| 202 | 208 | raise ValueError("engine must be either 'pandas' or 'bigframes'") | |
| 209 | + if value == "bigframes": | ||
| 210 | + warnings.warn( | ||
| 211 | + "The bigframes engine is deprecated. Please use %load_ext bigframes " | ||
| 212 | + "and the %%bqsql magic instead. " | ||
| 213 | + "See: https://dataframes.bigquery.dev/notebooks/getting_started/magics.html", | ||
| 214 | + FutureWarning, | ||
| 215 | + stacklevel=2, | ||
| 216 | + ) | ||
| 203 | 217 | self._engine = value | |
| 204 | 218 | ||
| 205 | 219 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,79 @@ | |||
| 1 | + # Copyright 2026 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 | + import pytest | ||
| 16 | + | ||
| 17 | + from bigquery_magics import bigquery as magics | ||
| 18 | + import bigquery_magics.config | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + @pytest.fixture(autouse=True) | ||
| 22 | + def mock_bq_client_and_credentials(mock_credentials): | ||
| 23 | + from unittest import mock | ||
| 24 | + | ||
| 25 | + with mock.patch("google.cloud.bigquery.Client", autospec=True): | ||
| 26 | + with mock.patch("bigquery_magics.core.create_bq_client", autospec=True): | ||
| 27 | + yield | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + def test_config_engine_setter_warning(): | ||
| 31 | + context = bigquery_magics.config.Context() | ||
| 32 | + with pytest.warns(FutureWarning, match="The bigframes engine is deprecated"): | ||
| 33 | + context.engine = "bigframes" | ||
| 34 | + | ||
| 35 | + | ||
| 36 | + def test_query_with_bigframes_warning(mock_ipython): | ||
| 37 | + # Mocking bigframes.pandas since it might not be installed | ||
| 38 | + from unittest import mock | ||
| 39 | + | ||
| 40 | + with mock.patch("bigquery_magics.bigquery.bpd") as mock_bpd: | ||
| 41 | + mock_bpd.read_gbq_query.return_value = mock.MagicMock() | ||
| 42 | + | ||
| 43 | + args = mock.MagicMock() | ||
| 44 | + args.engine = "bigframes" | ||
| 45 | + args.dry_run = False | ||
| 46 | + args.max_results = None | ||
| 47 | + args.destination_var = None | ||
| 48 | + args.destination_table = None | ||
| 49 | + | ||
| 50 | + with pytest.warns(FutureWarning, match="The bigframes engine is deprecated"): | ||
| 51 | + magics._query_with_bigframes("SELECT 1", [], args) | ||
| 52 | + | ||
| 53 | + | ||
| 54 | + def test_cell_magic_engine_bigframes_warning(mock_ipython): | ||
| 55 | + from unittest import mock | ||
| 56 | + | ||
| 57 | + from IPython.testing.globalipapp import get_ipython | ||
| 58 | + | ||
| 59 | + ip = get_ipython() | ||
| 60 | + if ip is None: | ||
| 61 | + from IPython.testing.globalipapp import start_ipython | ||
| 62 | + | ||
| 63 | + ip = start_ipython() | ||
| 64 | + | ||
| 65 | + ip.extension_manager.load_extension("bigquery_magics") | ||
| 66 | + | ||
| 67 | + # Mock the actual execution to avoid needing real credentials/data | ||
| 68 | + with mock.patch("bigquery_magics.bigquery.bpd") as mock_bpd: | ||
| 69 | + mock_bpd.read_gbq_query.return_value = mock.MagicMock() | ||
| 70 | + with pytest.warns(FutureWarning, match="The bigframes engine is deprecated"): | ||
| 71 | + ip.run_cell_magic("bigquery", "--engine bigframes", "SELECT 1") | ||
| 72 | + | ||
| 73 | + | ||
| 74 | + @pytest.fixture | ||
| 75 | + def mock_ipython(): | ||
| 76 | + from unittest import mock | ||
| 77 | + | ||
| 78 | + with mock.patch("bigquery_magics.bigquery.get_ipython") as mock_get_ipython: | ||
| 79 | + yield mock_get_ipython | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments