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

fix: timestamp precision in insert_rows #393

Merged
merged 3 commits into from Nov 23, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions google/cloud/bigquery/_helpers.py
Expand Up @@ -319,6 +319,7 @@ def _timestamp_to_json_row(value):
"""
if isinstance(value, datetime.datetime):
value = _microseconds_from_datetime(value) * 1e-6
value = round(value, 6)
tswast marked this conversation as resolved.
Show resolved Hide resolved
return value


Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test__helpers.py
Expand Up @@ -733,6 +733,13 @@ def test_w_datetime(self):
when = datetime.datetime(2016, 12, 20, 15, 58, 27, 339328)
self.assertEqual(self._call_fut(when), _microseconds_from_datetime(when) / 1e6)

def test_w_datetime_w_utc_zone(self):
from google.cloud._helpers import _microseconds_from_datetime
from google.cloud._helpers import UTC

when = datetime.datetime(2020, 11, 17, 1, 6, 52, 353795, tzinfo=UTC)
self.assertEqual(self._call_fut(when), _microseconds_from_datetime(when) / 1e6)


class Test_datetime_to_json(unittest.TestCase):
def _call_fut(self, value):
Expand Down