Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: exception was ignored while fetching the attribute __array_interface__ #2013

Closed
mwtoews opened this issue Jul 19, 2021 · 4 comments · Fixed by #2072
Closed

BUG: exception was ignored while fetching the attribute __array_interface__ #2013

mwtoews opened this issue Jul 19, 2021 · 4 comments · Fixed by #2072

Comments

@mwtoews
Copy link
Contributor

mwtoews commented Jul 19, 2021

This issue is essentially described here.

In a miniconda environment on any OS using a conda-forge channel with geopandas 0.9.0, shapely 1.7.1, pygeos 0.10.1 and numpy 1.21.0, take this example test_numpy_dep.py script:

import geopandas
from random import random
from shapely.geometry import Polygon

geoms = [Polygon((random(), random()) for _ in range(3)) for _ in range(3)]
gdf = geopandas.GeoDataFrame(geometry=geoms)

and run it via python -W all test_numpy_dep.py. The console will be flooded one warning per geometry, each showing:

C:\Users\mtoews\Miniconda3\envs\pyforge\lib\site-packages\geopandas_vectorized.py:106: 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)

(similar on Linux, I'm just happen to be sitting at Windows desktop now).

The relevant NumPy release note is titled "Exceptions will be raised during array-like creation". I'll admit I don't 100% follow the expected changes.

Note there is a related shapely deprecation warning, see #1659. Also, shapely 1.8 (not released yet) will deprecate the array interface.

Output of geopandas.show_versions()

SYSTEM INFO
-----------
python     : 3.9.6 | packaged by conda-forge | (default, Jul 11 2021, 03:37:25) [MSC v.1916 64 bit (AMD64)]
executable : C:\Users\mtoews\Miniconda3\envs\pyforge\python.exe
machine    : Windows-10-10.0.17134-SP0

GEOS, GDAL, PROJ INFO
---------------------
GEOS       : None
GEOS lib   : None
GDAL       : 3.3.1
GDAL data dir: None
PROJ       : 8.0.1
PROJ data dir: C:\Users\mtoews\Miniconda3\envs\pyforge\Library\share\proj

PYTHON DEPENDENCIES
-------------------
geopandas  : 0.9.0
pandas     : 1.2.5
fiona      : 1.8.20
numpy      : 1.21.0
shapely    : 1.7.1
rtree      : 0.9.7
pyproj     : 3.1.0
matplotlib : 3.4.2
mapclassify: 2.4.2
geopy      : None
psycopg2   : 2.9.1 (dt dec pq3 ext lo64)
geoalchemy2: None
pyarrow    : None
pygeos     : 0.10.1
@mwtoews
Copy link
Contributor Author

mwtoews commented Jul 19, 2021

On further inspection, this issue may need to be fixed in Shapely, see shapely/shapely#1173

@martinfleis
Copy link
Member

Thanks for the report! This shows up in our CI as well.

The optimal solution would be to fast track shapely 2.0 but I understand that will not happen :).

I guess the best way is to switch to AttributError as you suggest in shapely/shapely#1173. I am not sure we can fix this on geopandas side.

@erikmannerfelt
Copy link

This warning is also triggered in geoutils and xdem (which depend on GeoPandas) where we get more warnings than usual 😉

image

@jorisvandenbossche
Copy link
Member

As we are already silencing Shapely deprecation warnings for Shapely 1.8+, we can also silence the numpy warning for older Shapely releases (it can reuse the same context manager that is used throughout our code base). -> #2072

For some more context see numpy/numpy#17965, numpy/numpy#18197 (they initially raise an error instead of a warning)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants