Skip to content
12 changes: 3 additions & 9 deletions google/cloud/bigquery/_pandas_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,9 @@
if pandas is not None: # pragma: NO COVER

def _to_wkb():
# Create a closure that:
# - Adds a not-null check. This allows the returned function to
# be used directly with apply, unlike `shapely.wkb.dumps`.
# - Avoid extra work done by `shapely.wkb.dumps` that we don't need.
# - Caches the WKBWriter (and write method lookup :) )
# - Avoids adding WKBWriter, lgeos, and notnull to the module namespace.
from shapely.geos import WKBWriter, lgeos # type: ignore

write = WKBWriter(lgeos).write
from shapely import wkb # type: ignore

write = wkb.dumps
notnull = pandas.notnull

def _to_wkb(v):
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
_COORDINATE_REFERENCE_SYSTEM = "EPSG:4326"

try:
import shapely.geos # type: ignore
import shapely # type: ignore
except ImportError:
shapely = None
else:
_read_wkt = shapely.geos.WKTReader(shapely.geos.lgeos).read
_read_wkt = shapely.wkt.loads

import google.api_core.exceptions
from google.api_core.page_iterator import HTTPIterator
Expand Down