Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd047419

Browse files
authored
fix: inserting non-finite floats with insert_rows() (#728)
1 parentddd9ce7 commitd047419

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

‎google/cloud/bigquery/_helpers.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
importbase64
1818
importdatetime
1919
importdecimal
20+
importmath
2021
importre
2122

2223
fromgoogle.cloud._helpersimportUTC
@@ -305,7 +306,12 @@ def _int_to_json(value):
305306

306307
def_float_to_json(value):
307308
"""Coerce 'value' to an JSON-compatible representation."""
308-
returnvalueifvalueisNoneelsefloat(value)
309+
ifvalueisNone:
310+
returnNone
311+
elifmath.isnan(value)ormath.isinf(value):
312+
returnstr(value)
313+
else:
314+
returnfloat(value)
309315

310316

311317
def_decimal_to_json(value):

‎tests/unit/test__helpers.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,24 @@ def _call_fut(self, value):
656656

657657
return_float_to_json(value)
658658

659+
deftest_w_none(self):
660+
self.assertEqual(self._call_fut(None),None)
661+
659662
deftest_w_float(self):
660663
self.assertEqual(self._call_fut(1.23),1.23)
661664

665+
deftest_w_nan(self):
666+
result=self._call_fut(float("nan"))
667+
self.assertEqual(result.lower(),"nan")
668+
669+
deftest_w_infinity(self):
670+
result=self._call_fut(float("inf"))
671+
self.assertEqual(result.lower(),"inf")
672+
673+
deftest_w_negative_infinity(self):
674+
result=self._call_fut(float("-inf"))
675+
self.assertEqual(result.lower(),"-inf")
676+
662677

663678
classTest_decimal_to_json(unittest.TestCase):
664679
def_call_fut(self,value):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp