Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 8 commits
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
8 changes: 4 additions & 4 deletions docs/classic_client/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

"""

import datetime
from datetime import datetime, timezone
import pytest

from google.api_core.exceptions import DeadlineExceeded
Expand All @@ -39,7 +39,7 @@
from test_utils.system import unique_resource_id
from test_utils.retry import RetryErrors

from google.cloud._helpers import UTC

from google.cloud.bigtable import Client
from google.cloud.bigtable import enums

Expand All @@ -57,8 +57,8 @@
STORAGE_TYPE = enums.StorageType.SSD
LABEL_KEY = "python-snippet"
LABEL_STAMP = (
datetime.datetime.utcnow()
.replace(microsecond=0, tzinfo=UTC)
datetime.now(timezone.utc)
.replace(microsecond=0)
.strftime("%Y-%m-%dt%H-%M-%S")
)
LABELS = {LABEL_KEY: str(LABEL_STAMP)}
Expand Down
21 changes: 10 additions & 11 deletions docs/classic_client/snippets_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@

"""

import datetime
from datetime import datetime, timezone
import pytest

from google.api_core.exceptions import TooManyRequests
from google.api_core.exceptions import ServiceUnavailable
from test_utils.system import unique_resource_id
from test_utils.retry import RetryErrors

from google.cloud._helpers import UTC
from google.cloud.bigtable import Client
from google.cloud.bigtable import enums
from google.cloud.bigtable import column_family
Expand All @@ -54,8 +53,8 @@
STORAGE_TYPE = enums.StorageType.SSD
LABEL_KEY = "python-snippet"
LABEL_STAMP = (
datetime.datetime.utcnow()
.replace(microsecond=0, tzinfo=UTC)
datetime.now(timezone.utc)
.replace(microsecond=0)
.strftime("%Y-%m-%dt%H-%M-%S")
)
LABELS = {LABEL_KEY: str(LABEL_STAMP)}
Expand Down Expand Up @@ -179,7 +178,7 @@ def test_bigtable_write_read_drop_truncate():
value = "value_{}".format(i).encode()
row = table.row(row_key)
row.set_cell(
COLUMN_FAMILY_ID, col_name, value, timestamp=datetime.datetime.utcnow()
COLUMN_FAMILY_ID, col_name, value, timestamp=datetime.now(timezone.utc)
)
rows.append(row)
response = table.mutate_rows(rows)
Expand Down Expand Up @@ -270,7 +269,7 @@ def test_bigtable_mutations_batcher():
row_key = row_keys[0]
row = table.row(row_key)
row.set_cell(
COLUMN_FAMILY_ID, column_name, "value-0", timestamp=datetime.datetime.utcnow()
COLUMN_FAMILY_ID, column_name, "value-0", timestamp=datetime.now(timezone.utc)
)
batcher.mutate(row)
# Add a collections of rows
Expand All @@ -279,7 +278,7 @@ def test_bigtable_mutations_batcher():
row = table.row(row_keys[i])
value = "value_{}".format(i).encode()
row.set_cell(
COLUMN_FAMILY_ID, column_name, value, timestamp=datetime.datetime.utcnow()
COLUMN_FAMILY_ID, column_name, value, timestamp=datetime.now(timezone.utc)
)
rows.append(row)
batcher.mutate_rows(rows)
Expand Down Expand Up @@ -759,7 +758,7 @@ def test_bigtable_batcher_mutate_flush_mutate_rows():
row_key = b"row_key_1"
row = table.row(row_key)
row.set_cell(
COLUMN_FAMILY_ID, COL_NAME1, "value-0", timestamp=datetime.datetime.utcnow()
COLUMN_FAMILY_ID, COL_NAME1, "value-0", timestamp=datetime.now(timezone.utc)
)

# In batcher, mutate will flush current batch if it
Expand Down Expand Up @@ -967,12 +966,12 @@ def test_bigtable_row_data_cells_cell_value_cell_values():
value = b"value_in_col1"
row = Config.TABLE.row(b"row_key_1")
row.set_cell(
COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.datetime.utcnow()
COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.now(timezone.utc)
)
row.commit()

row.set_cell(
COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.datetime.utcnow()
COLUMN_FAMILY_ID, COL_NAME1, value, timestamp=datetime.now(timezone.utc)
)
row.commit()

Expand Down Expand Up @@ -1050,7 +1049,7 @@ def test_bigtable_row_setcell_rowkey():

cell_val = b"cell-val"
row.set_cell(
COLUMN_FAMILY_ID, COL_NAME1, cell_val, timestamp=datetime.datetime.utcnow()
COLUMN_FAMILY_ID, COL_NAME1, cell_val, timestamp=datetime.now(timezone.utc)
)
# [END bigtable_api_row_set_cell]

Expand Down
4 changes: 2 additions & 2 deletions samples/hello/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from ..utils import wait_for_table

# [START bigtable_hw_imports]
import datetime
from datetime import datetime, timezone

from google.cloud import bigtable
from google.cloud.bigtable import column_family
Expand Down Expand Up @@ -88,7 +88,7 @@ def main(project_id, instance_id, table_id):
row_key = f"greeting{i}".encode()
row = table.direct_row(row_key)
row.set_cell(
column_family_id, column, value, timestamp=datetime.datetime.utcnow(),
column_family_id, column, value, timestamp=datetime.now(timezone.utc),
)
rows.append(row)
table.mutate_rows(rows)
Expand Down
4 changes: 2 additions & 2 deletions samples/snippets/writes/write_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# [START bigtable_writes_batch]
import datetime
from datetime import datetime, timezone

from google.cloud import bigtable
from google.cloud.bigtable.batcher import MutationsBatcher
Expand All @@ -25,7 +25,7 @@ def write_batch(project_id, instance_id, table_id):
table = instance.table(table_id)

with MutationsBatcher(table=table) as batcher:
timestamp = datetime.datetime.utcnow()
timestamp = datetime.now(timezone.utc)
column_family_id = "stats_summary"

rows = [
Expand Down
4 changes: 2 additions & 2 deletions samples/snippets/writes/write_conditionally.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# [START bigtable_writes_conditional]
import datetime
from datetime import datetime, timezone

from google.cloud import bigtable
from google.cloud.bigtable import row_filters
Expand All @@ -24,7 +24,7 @@ def write_conditional(project_id, instance_id, table_id):
instance = client.instance(instance_id)
table = instance.table(table_id)

timestamp = datetime.datetime.utcnow()
timestamp = datetime.now(timezone.utc)
column_family_id = "stats_summary"

row_key = "phone#4c410523#20190501"
Expand Down
4 changes: 2 additions & 2 deletions samples/snippets/writes/write_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.

# [START bigtable_writes_simple]
import datetime
from datetime import datetime, timezone

from google.cloud import bigtable

Expand All @@ -24,7 +24,7 @@ def write_simple(project_id, instance_id, table_id):
instance = client.instance(instance_id)
table = instance.table(table_id)

timestamp = datetime.datetime.utcnow()
timestamp = datetime.now(timezone.utc)
column_family_id = "stats_summary"

row_key = "phone#4c410523#20190501"
Expand Down
7 changes: 2 additions & 5 deletions tests/system/v2_client/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import datetime
from datetime import datetime, timezone

import grpc
from google.api_core import exceptions
from google.cloud import exceptions as core_exceptions
from google.cloud._helpers import UTC
from test_utils import retry


Expand All @@ -41,7 +40,5 @@ def _retry_on_unavailable(exc):

def label_stamp():
return (
datetime.datetime.utcnow()
.replace(microsecond=0, tzinfo=UTC)
.strftime("%Y-%m-%dt%H-%M-%S")
datetime.now(timezone.utc).replace(microsecond=0).strftime("%Y-%m-%dt%H-%M-%S")
)
15 changes: 7 additions & 8 deletions tests/system/v2_client/test_data_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import datetime
from datetime import datetime, timedelta, timezone
import operator

import pytest
Expand Down Expand Up @@ -62,8 +62,8 @@ def rows_to_delete():
def test_table_read_rows_filter_millis(data_table):
from google.cloud.bigtable import row_filters

end = datetime.datetime.now()
start = end - datetime.timedelta(minutes=60)
end = datetime.now()
start = end - timedelta(minutes=60)
timestamp_range = row_filters.TimestampRange(start=start, end=end)
timefilter = row_filters.TimestampRangeFilter(timestamp_range)
row_data = data_table.read_rows(filter_=timefilter)
Expand Down Expand Up @@ -233,20 +233,19 @@ def test_table_read_row_large_cell(data_table, rows_to_delete, skip_on_emulator)
def _write_to_row(row1, row2, row3, row4):
from google.cloud._helpers import _datetime_from_microseconds
from google.cloud._helpers import _microseconds_from_datetime
from google.cloud._helpers import UTC
from google.cloud.bigtable.row_data import Cell

timestamp1 = datetime.datetime.utcnow().replace(tzinfo=UTC)
timestamp1 = datetime.now(timezone.utc)
timestamp1_micros = _microseconds_from_datetime(timestamp1)
# Truncate to millisecond granularity.
timestamp1_micros -= timestamp1_micros % 1000
timestamp1 = _datetime_from_microseconds(timestamp1_micros)
# 1000 microseconds is a millisecond
timestamp2 = timestamp1 + datetime.timedelta(microseconds=1000)
timestamp2 = timestamp1 + timedelta(microseconds=1000)
timestamp2_micros = _microseconds_from_datetime(timestamp2)
timestamp3 = timestamp1 + datetime.timedelta(microseconds=2000)
timestamp3 = timestamp1 + timedelta(microseconds=2000)
timestamp3_micros = _microseconds_from_datetime(timestamp3)
timestamp4 = timestamp1 + datetime.timedelta(microseconds=3000)
timestamp4 = timestamp1 + timedelta(microseconds=3000)
timestamp4_micros = _microseconds_from_datetime(timestamp4)

if row1 is not None:
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/v2_client/test_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import pytest

from ._testing import _make_credentials
from google.cloud._helpers import UTC

PROJECT_ID = "project-id"
INSTANCE_ID = "instance-id"
Expand All @@ -38,7 +37,7 @@


def _make_timestamp():
return datetime.datetime.utcnow().replace(tzinfo=UTC)
return datetime.datetime.now(datetime.timezone.utc)


def _make_table_admin_client():
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/v2_client/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def test_cluster_create():
from google.cloud.bigtable_admin_v2.types import instance as instance_v2_pb2
from google.cloud.bigtable.enums import StorageType

NOW = datetime.datetime.utcnow()
NOW = datetime.datetime.now(datetime.timezone.utc)
NOW_PB = _datetime_to_pb_timestamp(NOW)
credentials = _make_credentials()
client = _make_client(project=PROJECT, credentials=credentials, admin=True)
Expand Down Expand Up @@ -475,7 +475,7 @@ def test_cluster_create_w_cmek():
from google.cloud.bigtable_admin_v2.types import instance as instance_v2_pb2
from google.cloud.bigtable.enums import StorageType

NOW = datetime.datetime.utcnow()
NOW = datetime.datetime.now(datetime.timezone.utc)
NOW_PB = _datetime_to_pb_timestamp(NOW)
credentials = _make_credentials()
client = _make_client(project=PROJECT, credentials=credentials, admin=True)
Expand Down Expand Up @@ -535,7 +535,7 @@ def test_cluster_create_w_autoscaling():
from google.cloud.bigtable_admin_v2.types import instance as instance_v2_pb2
from google.cloud.bigtable.enums import StorageType

NOW = datetime.datetime.utcnow()
NOW = datetime.datetime.now(datetime.timezone.utc)
NOW_PB = _datetime_to_pb_timestamp(NOW)
credentials = _make_credentials()
client = _make_client(project=PROJECT, credentials=credentials, admin=True)
Expand Down Expand Up @@ -602,7 +602,7 @@ def test_cluster_update():
)
from google.cloud.bigtable.enums import StorageType

NOW = datetime.datetime.utcnow()
NOW = datetime.datetime.now(datetime.timezone.utc)
NOW_PB = _datetime_to_pb_timestamp(NOW)

credentials = _make_credentials()
Expand Down Expand Up @@ -669,7 +669,7 @@ def test_cluster_update_w_autoscaling():
)
from google.cloud.bigtable.enums import StorageType

NOW = datetime.datetime.utcnow()
NOW = datetime.datetime.now(datetime.timezone.utc)
NOW_PB = _datetime_to_pb_timestamp(NOW)

credentials = _make_credentials()
Expand Down Expand Up @@ -728,7 +728,7 @@ def test_cluster_update_w_partial_autoscaling_config():
)
from google.cloud.bigtable.enums import StorageType

NOW = datetime.datetime.utcnow()
NOW = datetime.datetime.now(datetime.timezone.utc)
NOW_PB = _datetime_to_pb_timestamp(NOW)

credentials = _make_credentials()
Expand Down Expand Up @@ -812,7 +812,7 @@ def test_cluster_update_w_both_manual_and_autoscaling():
)
from google.cloud.bigtable.enums import StorageType

NOW = datetime.datetime.utcnow()
NOW = datetime.datetime.now(datetime.timezone.utc)
NOW_PB = _datetime_to_pb_timestamp(NOW)

credentials = _make_credentials()
Expand Down Expand Up @@ -873,7 +873,7 @@ def test_cluster_disable_autoscaling():
from google.cloud.bigtable.instance import Instance
from google.cloud.bigtable.enums import StorageType

NOW = datetime.datetime.utcnow()
NOW = datetime.datetime.now(datetime.timezone.utc)
NOW_PB = _datetime_to_pb_timestamp(NOW)
credentials = _make_credentials()
client = _make_client(project=PROJECT, credentials=credentials, admin=True)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/v2_client/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def _instance_api_response_for_create():
)
from google.cloud.bigtable_admin_v2.types import instance

NOW = datetime.datetime.utcnow()
NOW = datetime.datetime.now(datetime.timezone.utc)
NOW_PB = _datetime_to_pb_timestamp(NOW)
metadata = messages_v2_pb2.CreateInstanceMetadata(request_time=NOW_PB)
type_url = "type.googleapis.com/{}".format(
Expand Down Expand Up @@ -503,7 +503,7 @@ def _instance_api_response_for_update():
)
from google.cloud.bigtable_admin_v2.types import instance

NOW = datetime.datetime.utcnow()
NOW = datetime.datetime.now(datetime.timezone.utc)
NOW_PB = _datetime_to_pb_timestamp(NOW)
metadata = messages_v2_pb2.UpdateInstanceMetadata(request_time=NOW_PB)
type_url = "type.googleapis.com/{}".format(
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/v2_client/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,13 +1378,12 @@ def test_table_backup_factory_defaults():

def test_table_backup_factory_non_defaults():
import datetime
from google.cloud._helpers import UTC
from google.cloud.bigtable.backup import Backup
from google.cloud.bigtable.instance import Instance

instance = Instance(INSTANCE_ID, None)
table = _make_table(TABLE_ID, instance)
timestamp = datetime.datetime.utcnow().replace(tzinfo=UTC)
timestamp = datetime.datetime.now(datetime.timezone.utc)
backup = table.backup(
BACKUP_ID,
cluster_id=CLUSTER_ID,
Expand Down
Loading