Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1cb3e55

Browse files
authored
fix: use REST API in cell magic when requested (#892)
Fixes#876.The `--use_rest_api` option did not work as expected and this commit fixes it.**PR checklist:**- [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-bigquery/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea- [x] Ensure the tests and linter pass- [x] Code coverage does not decrease (if any source code was changed)- [x] Appropriate docs were updated (if necessary)
1 parent72a52f0 commit1cb3e55

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

‎google/cloud/bigquery/magics/magics.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,9 @@ def _cell_magic(line, query):
671671
_handle_error(ex,args.destination_var)
672672
return
673673

674-
result=rows.to_dataframe(bqstorage_client=bqstorage_client)
674+
result=rows.to_dataframe(
675+
bqstorage_client=bqstorage_client,create_bqstorage_client=False,
676+
)
675677
ifargs.destination_var:
676678
IPython.get_ipython().push({args.destination_var:result})
677679
return
@@ -728,11 +730,15 @@ def _cell_magic(line, query):
728730

729731
ifmax_results:
730732
result=query_job.result(max_results=max_results).to_dataframe(
731-
bqstorage_client=bqstorage_client,progress_bar_type=progress_bar
733+
bqstorage_client=None,
734+
create_bqstorage_client=False,
735+
progress_bar_type=progress_bar,
732736
)
733737
else:
734738
result=query_job.to_dataframe(
735-
bqstorage_client=bqstorage_client,progress_bar_type=progress_bar
739+
bqstorage_client=bqstorage_client,
740+
create_bqstorage_client=False,
741+
progress_bar_type=progress_bar,
736742
)
737743

738744
ifargs.destination_var:

‎tests/unit/test_magics.py‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,9 @@ def warning_match(warning):
660660
assertclient_info.user_agent=="ipython-"+IPython.__version__
661661

662662
query_job_mock.to_dataframe.assert_called_once_with(
663-
bqstorage_client=bqstorage_instance_mock,progress_bar_type="tqdm"
663+
bqstorage_client=bqstorage_instance_mock,
664+
create_bqstorage_client=mock.ANY,
665+
progress_bar_type="tqdm",
664666
)
665667

666668
assertisinstance(return_value,pandas.DataFrame)
@@ -703,7 +705,9 @@ def test_bigquery_magic_with_rest_client_requested(monkeypatch):
703705

704706
bqstorage_mock.assert_not_called()
705707
query_job_mock.to_dataframe.assert_called_once_with(
706-
bqstorage_client=None,progress_bar_type="tqdm"
708+
bqstorage_client=None,
709+
create_bqstorage_client=False,
710+
progress_bar_type="tqdm",
707711
)
708712

709713
assertisinstance(return_value,pandas.DataFrame)
@@ -757,7 +761,12 @@ def test_bigquery_magic_w_max_results_valid_calls_queryjob_result():
757761
client_query_mock.return_value=query_job_mock
758762
ip.run_cell_magic("bigquery","--max_results=5",sql)
759763

760-
query_job_mock.result.assert_called_with(max_results=5)
764+
query_job_mock.result.assert_called_with(max_results=5)
765+
query_job_mock.result.return_value.to_dataframe.assert_called_once_with(
766+
bqstorage_client=None,
767+
create_bqstorage_client=False,
768+
progress_bar_type=mock.ANY,
769+
)
761770

762771

763772
@pytest.mark.usefixtures("ipython_interactive")
@@ -929,7 +938,7 @@ def test_bigquery_magic_w_table_id_and_bqstorage_client():
929938

930939
ip.run_cell_magic("bigquery","--max_results=5",table_id)
931940
row_iterator_mock.to_dataframe.assert_called_once_with(
932-
bqstorage_client=bqstorage_instance_mock
941+
bqstorage_client=bqstorage_instance_mock,create_bqstorage_client=mock.ANY,
933942
)
934943

935944

@@ -1246,7 +1255,9 @@ def test_bigquery_magic_w_progress_bar_type_w_context_setter(monkeypatch):
12461255

12471256
bqstorage_mock.assert_not_called()
12481257
query_job_mock.to_dataframe.assert_called_once_with(
1249-
bqstorage_client=None,progress_bar_type=magics.context.progress_bar_type
1258+
bqstorage_client=None,
1259+
create_bqstorage_client=False,
1260+
progress_bar_type=magics.context.progress_bar_type,
12501261
)
12511262

12521263
assertisinstance(return_value,pandas.DataFrame)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp