Skip to content

Commit 3ec190d

Browse files
committed
Fix object lookups for Python 3.6
1 parent b1d3db2 commit 3ec190d

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

singlestoredb/http/connection.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,37 @@ def b64decode_converter(
163163
return converter(b64decode(x))
164164

165165

166+
shapely_Point = None
167+
shapely_Polygon = None
168+
shapely_LineString = None
169+
np_ndarray = None
170+
pygeos_Geometry = None
171+
172+
173+
if has_shapely:
174+
shapely_Point = shapely.Point
175+
shapely_Polygon = shapely.Polygon
176+
shapely_LineString = shapely.LineString
177+
178+
if has_numpy:
179+
np_ndarray = np.ndarray
180+
181+
if has_pygeos:
182+
pygeos_Geometry = pygeos.Geometry
183+
184+
166185
def convert_special_type(arg: Any) -> Any:
167186
"""Convert special data type objects."""
168187
dtype = type(arg)
169-
if has_numpy and dtype is np.ndarray:
188+
if dtype is np_ndarray:
170189
return arg.tobytes()
171-
if has_shapely and dtype is getattr(shapely, 'Point', None):
190+
if dtype is shapely_Point:
172191
return shapely.wkt.dumps(arg)
173-
if has_shapely and dtype is getattr(shapely, 'Polygon', None):
192+
if dtype is shapely_Polygon:
174193
return shapely.wkt.dumps(arg)
175-
if has_shapely and dtype is getattr(shapely, 'LineString', None):
194+
if dtype is shapely_LineString:
176195
return shapely.wkt.dumps(arg)
177-
if has_pygeos and dtype is pygeos.Geometry:
196+
if dtype is pygeos_Geometry:
178197
return pygeos.io.to_wkt(arg)
179198
return arg
180199

0 commit comments

Comments
 (0)