Skip to content

Commit

Permalink
Fix: refactor to adapt to changes to shapely dependency (#1376)
Browse files Browse the repository at this point in the history
* fix: refactored to account for changes in dependency

* Removes comment and ensures linting success

* refactor to use loads() function

* fix: refactors to account for changes to shapely dependency

* fix: refactors to account for changes to shapely dependency

* blacken the code

* add mypy ignore flag for shapely import
  • Loading branch information
chalmerlowe committed Oct 5, 2022
1 parent 78db9ea commit 2afd278
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
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

0 comments on commit 2afd278

Please sign in to comment.