Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate(bigquery): deprecate client.dataset() in favor of DatasetReference #7753

Merged
merged 4 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions bigquery/google/cloud/bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import math
import os
import tempfile
import textwrap
import uuid
import warnings

Expand Down Expand Up @@ -354,7 +355,18 @@ def list_datasets(
)

def dataset(self, dataset_id, project=None):
"""Construct a reference to a dataset.
"""Deprecated: Construct a reference to a dataset.

This method is deprecated. Construct a
:class:`~google.cloud.bigquery.dataset.DatasetReference` using its
constructor or use a string where previously a reference object was
used.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use the standard Sphinx directive for deprecations?
The text itself is already clear, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't appear to change formatting all that much:

image

Pushed the change in case it makes things a little more machine-readable or something, though.


As ``google-cloud-bigquery`` version 1.7.0, all client methods that
tswast marked this conversation as resolved.
Show resolved Hide resolved
take a :class:`~google.cloud.bigquery.dataset.DatasetReference` or
:class:`~google.cloud.bigquery.table.TableReference` also take a
string in standard SQL format, e.g. ``project.dataset_id`` or
``project.dataset_id.table_id``.

Args:
dataset_id (str): ID of the dataset.
Expand All @@ -370,6 +382,15 @@ def dataset(self, dataset_id, project=None):
if project is None:
project = self.project

warnings.warn(
textwrap.fill(
"Client.dataset is deprecated and will be removed in a future version. "
"Use a string like 'my_project.my_dataset' or a "
"cloud.google.bigquery.DatasetReference object, instead."
),
PendingDeprecationWarning,
stacklevel=2,
)
return DatasetReference(project, dataset_id)

def _create_bqstorage_client(self):
Expand Down Expand Up @@ -419,7 +440,7 @@ def create_dataset(

>>> from google.cloud import bigquery
>>> client = bigquery.Client()
>>> dataset = bigquery.Dataset(client.dataset('my_dataset'))
>>> dataset = bigquery.Dataset('my_project.my_dataset')
>>> dataset = client.create_dataset(dataset)

"""
Expand Down Expand Up @@ -2584,7 +2605,7 @@ def list_partitions(self, table, retry=DEFAULT_RETRY, timeout=None):
) as guard:
meta_table = self.get_table(
TableReference(
self.dataset(table.dataset_id, project=table.project),
DatasetReference(table.project, table.dataset_id),
"%s$__PARTITIONS_SUMMARY__" % table.table_id,
),
retry=retry,
Expand Down
3 changes: 2 additions & 1 deletion bigquery/google/cloud/bigquery/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
from google.api_core.exceptions import NotFound
import google.auth
from google.cloud import bigquery
import google.cloud.bigquery.dataset
from google.cloud.bigquery.dbapi import _helpers
import six

Expand Down Expand Up @@ -534,7 +535,7 @@ def _cell_magic(line, query):
)
dataset_id, table_id = split
job_config.allow_large_results = True
dataset_ref = client.dataset(dataset_id)
dataset_ref = bigquery.dataset.DatasetReference(client.project, dataset_id)
destination_table_ref = dataset_ref.table(table_id)
job_config.destination = destination_table_ref
job_config.create_disposition = "CREATE_IF_NEEDED"
Expand Down
Loading