Reading a polygon shapefile with geopandas I got a strange error. I found out it is a normally hidden warning about another error, which I saw only because I turned warnings to errors. It also appears when creating a GeoDataFrame:
import geopandas as gpd
from shapely.geometry import Polygon
import random
import warnings
warnings.filterwarnings('error')
geoms = [Polygon(
(random.random(), random.random())
for p in range(10)) for id in range(10)]
gdf = gpd.GeoDataFrame(geometry=geoms)
Output:
Traceback (most recent call last):
File "C:\Daten2\Anaconda\lib\site-packages\shapely\geometry\polygon.py", line 300, in __array_interface__
raise NotImplementedError(
NotImplementedError: A polygon does not itself provide the array interface. Its rings do.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "error.py", line 11, in <module>
gdf = gpd.GeoDataFrame(geometry=geoms)
File "C:\Daten2\Anaconda\lib\site-packages\geopandas\geodataframe.py", line 167, in __init__
self.set_geometry(geometry, inplace=True)
File "C:\Daten2\Anaconda\lib\site-packages\geopandas\geodataframe.py", line 295, in set_geometry
level = _ensure_geometry(level, crs=crs)
File "C:\Daten2\Anaconda\lib\site-packages\geopandas\geodataframe.py", line 43, in _ensure_geometry
out = from_shapely(data, crs=crs)
File "C:\Daten2\Anaconda\lib\site-packages\geopandas\array.py", line 168, in from_shapely
return GeometryArray(vectorized.from_shapely(data), crs=crs)
File "C:\Daten2\Anaconda\lib\site-packages\geopandas\_vectorized.py", line 142, in from_shapely
aout[:] = out
DeprecationWarning: An exception was ignored while fetching the attribute `__array_interface__` from an object of type 'Polygon'. With the exception of `AttributeError` NumPy will always raise this exception in the future. Raise this deprecation warning to see the original exception. (Warning added NumPy 1.21)
The warning occurs in the line
aout[:] = out
of a geopandas module. out is a list of shapely.geometry.polygon.Polygon, while aout is a numpy array of the same length with dtype object, containing Nones.
So I'm curious what is happening here?
pm
does? Excerpt plz. Your issue may be Python scope related. Very difficult or impossible to guess from current provided infos as too incompleteimport sys
(then next line)print(sys.executable)
..if they give you different results, it means you need to specify the interpreter you're using in your scripted environment.cd C:\Daten2\G991
python -i g991edat.py
. I checked sys.executable, sys.path and os.environment and can't detect any difference.