Repository: googleapis/google-cloud-python

Issue:
Bigtable: cleanup and warnings about support for backwards compatible features that will be discontinued.
Remove unused [variable](https://github.com/googleapis/google-cloud-python/blob/master/bigtable/google/cloud/bigtable/instance.py#L33).

Add `DeprecationWarnings` for backwards compatible features that should/will go away.

- `table.yield_rows()`
- `location_id`, `serve_nodes` and `default_storage_type` parameters in `instance.create()`


Discussion:

Resolving patch:
diff --git a/bigtable/google/cloud/bigtable/instance.py b/bigtable/google/cloud/bigtable/instance.py
--- a/bigtable/google/cloud/bigtable/instance.py
+++ b/bigtable/google/cloud/bigtable/instance.py
@@ -29,12 +29,18 @@
 
 from google.cloud.bigtable.policy import Policy
 
+import warnings
 
-_EXISTING_INSTANCE_LOCATION_ID = "see-existing-cluster"
 _INSTANCE_NAME_RE = re.compile(
     r"^projects/(?P<project>[^/]+)/" r"instances/(?P<instance_id>[a-z][-a-z0-9]*)$"
 )
 
+_INSTANCE_CREATE_WARNING = """
+Use of `instance.create({0}, {1}, {2})` will be depricated.
+Please replace with
+`cluster = instance.cluster({0}, {1}, {2})`
+`instance.create(clusters=[cluster])`."""
+
 
 class Instance(object):
     """Representation of a Google Cloud Bigtable Instance.
@@ -276,6 +282,14 @@ def create(
         """
 
         if clusters is None:
+            warnings.warn(
+                _INSTANCE_CREATE_WARNING.format(
+                    "location_id", "serve_nodes", "default_storage_type"
+                ),
+                DeprecationWarning,
+                stacklevel=2,
+            )
+
             cluster_id = "{}-cluster".format(self.instance_id)
 
             clusters = [
diff --git a/bigtable/google/cloud/bigtable/table.py b/bigtable/google/cloud/bigtable/table.py
--- a/bigtable/google/cloud/bigtable/table.py
+++ b/bigtable/google/cloud/bigtable/table.py
@@ -42,6 +42,8 @@
     bigtable_table_admin_pb2 as table_admin_messages_v2_pb2,
 )
 
+import warnings
+
 
 # Maximum number of mutations in bulk (MutateRowsRequest message):
 # (https://cloud.google.com/bigtable/docs/reference/data/rpc/
@@ -467,6 +469,11 @@ def yield_rows(self, **kwargs):
         :rtype: :class:`.PartialRowData`
         :returns: A :class:`.PartialRowData` for each row returned
         """
+        warnings.warn(
+            "`yield_rows()` is depricated; use `red_rows()` instead",
+            DeprecationWarning,
+            stacklevel=2,
+        )
         return self.read_rows(**kwargs)
 
     def mutate_rows(self, rows, retry=DEFAULT_RETRY):


Test patch:
diff --git a/bigtable/tests/unit/test_instance.py b/bigtable/tests/unit/test_instance.py
--- a/bigtable/tests/unit/test_instance.py
+++ b/bigtable/tests/unit/test_instance.py
@@ -292,6 +292,7 @@ def _instance_api_response_for_create(self):
     def test_create(self):
         from google.cloud.bigtable import enums
         from google.cloud.bigtable_admin_v2.types import instance_pb2
+        import warnings
 
         credentials = _make_credentials()
         client = self._make_client(
@@ -308,7 +309,10 @@ def test_create(self):
         client._instance_admin_client = instance_api
         serve_nodes = 3
 
-        result = instance.create(location_id=self.LOCATION_ID, serve_nodes=serve_nodes)
+        with warnings.catch_warnings(record=True) as warned:
+            result = instance.create(
+                location_id=self.LOCATION_ID, serve_nodes=serve_nodes
+            )
 
         cluster_pb = instance_pb2.Cluster(
             location=instance_api.location_path(self.PROJECT, self.LOCATION_ID),
@@ -328,6 +332,9 @@ def test_create(self):
             clusters={cluster_id: cluster_pb},
         )
 
+        self.assertEqual(len(warned), 1)
+        self.assertIs(warned[0].category, DeprecationWarning)
+
         self.assertIs(result, response)
 
     def test_create_w_clusters(self):
diff --git a/bigtable/tests/unit/test_table.py b/bigtable/tests/unit/test_table.py
--- a/bigtable/tests/unit/test_table.py
+++ b/bigtable/tests/unit/test_table.py
@@ -752,6 +752,7 @@ def test_read_retry_rows(self):
     def test_yield_retry_rows(self):
         from google.cloud.bigtable_v2.gapic import bigtable_client
         from google.cloud.bigtable_admin_v2.gapic import bigtable_table_admin_client
+        import warnings
 
         data_api = bigtable_client.BigtableClient(mock.Mock())
         table_api = bigtable_table_admin_client.BigtableTableAdminClient(mock.Mock())
@@ -799,8 +800,14 @@ def test_yield_retry_rows(self):
         )
 
         rows = []
-        for row in table.yield_rows(start_key=self.ROW_KEY_1, end_key=self.ROW_KEY_2):
-            rows.append(row)
+        with warnings.catch_warnings(record=True) as warned:
+            for row in table.yield_rows(
+                start_key=self.ROW_KEY_1, end_key=self.ROW_KEY_2
+            ):
+                rows.append(row)
+
+        self.assertEqual(len(warned), 1)
+        self.assertIs(warned[0].category, DeprecationWarning)
 
         result = rows[1]
         self.assertEqual(result.row_key, self.ROW_KEY_2)
@@ -810,6 +817,7 @@ def test_yield_rows_with_row_set(self):
         from google.cloud.bigtable_admin_v2.gapic import bigtable_table_admin_client
         from google.cloud.bigtable.row_set import RowSet
         from google.cloud.bigtable.row_set import RowRange
+        import warnings
 
         data_api = bigtable_client.BigtableClient(mock.Mock())
         table_api = bigtable_table_admin_client.BigtableTableAdminClient(mock.Mock())
@@ -866,8 +874,13 @@ def test_yield_rows_with_row_set(self):
             RowRange(start_key=self.ROW_KEY_1, end_key=self.ROW_KEY_2)
         )
         row_set.add_row_key(self.ROW_KEY_3)
-        for row in table.yield_rows(row_set=row_set):
-            rows.append(row)
+
+        with warnings.catch_warnings(record=True) as warned:
+            for row in table.yield_rows(row_set=row_set):
+                rows.append(row)
+
+        self.assertEqual(len(warned), 1)
+        self.assertIs(warned[0].category, DeprecationWarning)
 
         self.assertEqual(rows[0].row_key, self.ROW_KEY_1)
         self.assertEqual(rows[1].row_key, self.ROW_KEY_2)