Skip to content

Commit 86c77ef

Browse files
sonlactseaver
authored andcommitted
Add is_nullable method to check for NULLABLE mode (#3620)
Resolves: #3548
1 parent d07365f commit 86c77ef

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

bigquery/google/cloud/bigquery/dbapi/cursor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _set_description(self, schema):
7676
internal_size=None,
7777
precision=None,
7878
scale=None,
79-
null_ok=field.mode == 'NULLABLE')
79+
null_ok=field.is_nullable)
8080
for field in schema])
8181

8282
def _set_rowcount(self, query_results):

bigquery/google/cloud/bigquery/schema.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ def mode(self):
6565
"""
6666
return self._mode
6767

68+
@property
69+
def is_nullable(self):
70+
"""Check whether 'mode' is 'nullable'."""
71+
return self._mode == 'NULLABLE'
72+
6873
@property
6974
def description(self):
7075
"""Optional[str]: Description for the field."""

bigquery/tests/unit/test_schema.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ def test_mode_property(self):
7474
schema_field = self._make_one('again', 'FLOAT', mode=mode)
7575
self.assertIs(schema_field.mode, mode)
7676

77+
def test_is_nullable(self):
78+
mode = 'NULLABLE'
79+
schema_field = self._make_one('test', 'FLOAT', mode=mode)
80+
self.assertTrue(schema_field.is_nullable)
81+
82+
def test_is_not_nullable(self):
83+
mode = 'REPEATED'
84+
schema_field = self._make_one('test', 'FLOAT', mode=mode)
85+
self.assertFalse(schema_field.is_nullable)
86+
7787
def test_description_property(self):
7888
description = 'It holds some data.'
7989
schema_field = self._make_one(

0 commit comments

Comments
 (0)