Skip to content

Commit cec97ff

Browse files
committed
deprecate(bigquery): deprecate client.dataset() in favor of DatasetReference
Now that all client methods that take a `DatasetReference` or `TableReference` also take a string, the `client.dataset()` method is unnecessary and confusing.
1 parent 0280a94 commit cec97ff

File tree

3 files changed

+105
-51
lines changed

3 files changed

+105
-51
lines changed

bigquery/google/cloud/bigquery/client.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import math
3333
import os
3434
import tempfile
35+
import textwrap
3536
import uuid
3637
import warnings
3738

@@ -354,7 +355,18 @@ def list_datasets(
354355
)
355356

356357
def dataset(self, dataset_id, project=None):
357-
"""Construct a reference to a dataset.
358+
"""Deprecated: Construct a reference to a dataset.
359+
360+
This method is deprecated. Construct a
361+
:class:`~google.cloud.bigquery.dataset.DatasetReference` using its
362+
constructor or use a string where previously a reference object was
363+
used.
364+
365+
As ``google-cloud-bigquery`` version 1.7.0, all client methods that
366+
take a :class:`~google.cloud.bigquery.dataset.DatasetReference` or
367+
:class:`~google.cloud.bigquery.table.TableReference` also take a
368+
string in standard SQL format, e.g. ``project.dataset_id`` or
369+
``project.dataset_id.table_id``.
358370
359371
Args:
360372
dataset_id (str): ID of the dataset.
@@ -370,6 +382,15 @@ def dataset(self, dataset_id, project=None):
370382
if project is None:
371383
project = self.project
372384

385+
warnings.warn(
386+
textwrap.fill(
387+
"Client.dataset is deprecated and will be removed in a future version. "
388+
"Use a string like 'my_project.my_dataset' or a "
389+
"cloud.google.bigquery.DatasetReference object, instead."
390+
),
391+
PendingDeprecationWarning,
392+
stacklevel=2,
393+
)
373394
return DatasetReference(project, dataset_id)
374395

375396
def _create_bqstorage_client(self):
@@ -419,7 +440,7 @@ def create_dataset(
419440
420441
>>> from google.cloud import bigquery
421442
>>> client = bigquery.Client()
422-
>>> dataset = bigquery.Dataset(client.dataset('my_dataset'))
443+
>>> dataset = bigquery.Dataset('my_project.my_dataset')
423444
>>> dataset = client.create_dataset(dataset)
424445
425446
"""
@@ -2584,7 +2605,7 @@ def list_partitions(self, table, retry=DEFAULT_RETRY, timeout=None):
25842605
) as guard:
25852606
meta_table = self.get_table(
25862607
TableReference(
2587-
self.dataset(table.dataset_id, project=table.project),
2608+
DatasetReference(table.project, table.dataset_id),
25882609
"%s$__PARTITIONS_SUMMARY__" % table.table_id,
25892610
),
25902611
retry=retry,

bigquery/google/cloud/bigquery/magics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
from google.api_core.exceptions import NotFound
154154
import google.auth
155155
from google.cloud import bigquery
156+
import google.cloud.bigquery.dataset
156157
from google.cloud.bigquery.dbapi import _helpers
157158
import six
158159

@@ -534,7 +535,7 @@ def _cell_magic(line, query):
534535
)
535536
dataset_id, table_id = split
536537
job_config.allow_large_results = True
537-
dataset_ref = client.dataset(dataset_id)
538+
dataset_ref = bigquery.dataset.DatasetReference(client.project, dataset_id)
538539
destination_table_ref = dataset_ref.table(table_id)
539540
job_config.destination = destination_table_ref
540541
job_config.create_disposition = "CREATE_IF_NEEDED"

0 commit comments

Comments
 (0)