Trevor
March 15, 2022, 2:55am
1
I updated to PyGMT 0.6 today, and using Python 3.9.10 (see complete list below). I’m getting a lot of these warnings with several pygmt commands …
FutureWarning: pandas.Int64Index is deprecated and will be removed from pandas in a future version. Use pandas.Index with the appropriate dtype instead.
Anybody else experiencing this?
Thanks, Trevor.
Complete list of dependency information:
numpy: 1.22.3
pandas: 1.4.1
xarray: 2022.3.0
netCDF4: 1.5.8
packaging: 21.3
ghostscript: 9.54.0
gmt: 6.3.0
I have not encountered this warning. I suspect that pandas was also updated in your environment when updating PyGMT. This warning was introduced by pandas in 1.4.0 (see https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Int64Index.html?highlight=int64index ).
I was hoping this would be fixed in v0.7 … alas not. This is still the warning:
FutureWarning: pandas.Int64Index is deprecated and will be removed from pandas in a future version. Use pandas.Index with the appropriate dtype instead.
FYI, pygmt.show_versions() gives …
PyGMT information:
version: v0.7.0
System information:
python: 3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 06:57:19) [MSC v.1929 64 bit (AMD64)]
executable: C:\Users\ … \python.exe
machine: Windows-10-10.0.19044-SP0
Dependency information:
numpy: 1.22.4
pandas: 1.4.2
xarray: 2022.3.0
netCDF4: 1.6.0
packaging: 21.3
geopandas: 0.10.2
ghostscript: 9.54.0
gmt: 6.4.0
GMT library information:
binary dir: C:/Users/ … /Anaconda3/envs/ …
cores: 12
grid layout: rows
library path: C:/Users/ … /Library/bin/gmt.dll
padding: 2
plugin dir: C:/Users/ … /Library/bin/gmt_plugins
share dir: C:/Users/ … /Library/share/gmt
version: 6.4.0
Are you getting these warnings using pandas objects that were created by PyGMT or separately? If they were created by PyGMT, what function did you use to create them?
The warning is raised by geopandas, not PyGMT. So there is nothing we can do on the PyGMT side. But it’s possible to suppress the warning following the instructions in
opened 02:51AM - 10 Jun 22 UTC
closed 04:23AM - 10 Jun 22 UTC
bug
upstream
**Description of the problem**
Since v.0.5.0 when calling `fig.plot()` with a s… hapefile, read in with `geopandas.read_file`, you get the following warning:
```
/usr/share/miniconda3/envs/pygmt/lib/python3.10/site-packages/geopandas/io/file.py:362: FutureWarning: pandas.Int64Index is deprecated and will be removed from pandas in a future version. Use pandas.Index with the appropriate dtype instead.
pd.Int64Index,
```
When plotting lots of shapefiles, these warnings take up lots of space in the output.
The warning can be seen in the [Roads](https://www.pygmt.org/latest/gallery/lines/roads.html) example in the gallery.
Is there a way to suppress these warnings? Apparently this will be fixed in the next release of geopandas, as discuss [here](https://github.com/geopandas/geopandas/issues/2347).
**Full code that generated the error**
```python
import geopandas as gpd
import pygmt
# Read shapefile data using geopandas
gdf = gpd.read_file(
"http://www2.census.gov/geo/tiger/TIGER2015/PRISECROADS/tl_2015_15_prisecroads.zip"
)
# The dataset contains different road types listed in the RTTYP column,
# here we select the following ones to plot:
roads_common = gdf[gdf.RTTYP == "M"] # Common name roads
roads_state = gdf[gdf.RTTYP == "S"] # State recognized roads
roads_interstate = gdf[gdf.RTTYP == "I"] # Interstate roads
fig = pygmt.Figure()
# Define target region around O'ahu (Hawai'i)
region = [-158.3, -157.6, 21.2, 21.75] # xmin, xmax, ymin, ymax
title = r"Main roads of O\047ahu (Hawai\047i)" # \047 is octal code for '
fig.basemap(region=region, projection="M12c", frame=["af", f'WSne+t"{title}"'])
fig.coast(land="gray", water="dodgerblue4", shorelines="1p,black")
# Plot the individual road types with different pen settings and assign labels
# which are displayed in the legend
fig.plot(data=roads_common, pen="5p,dodgerblue", label="CommonName")
fig.plot(data=roads_state, pen="2p,gold", label="StateRecognized")
fig.plot(data=roads_interstate, pen="2p,red", label="Interstate")
# Add legend
fig.legend()
fig.show()
```
**Full error message**
```
/usr/share/miniconda3/envs/pygmt/lib/python3.10/site-packages/geopandas/io/file.py:362: FutureWarning: pandas.Int64Index is deprecated and will be removed from pandas in a future version. Use pandas.Index with the appropriate dtype instead.
pd.Int64Index,
/usr/share/miniconda3/envs/pygmt/lib/python3.10/site-packages/geopandas/io/file.py:362: FutureWarning: pandas.Int64Index is deprecated and will be removed from pandas in a future version. Use pandas.Index with the appropriate dtype instead.
pd.Int64Index,
/usr/share/miniconda3/envs/pygmt/lib/python3.10/site-packages/geopandas/io/file.py:362: FutureWarning: pandas.Int64Index is deprecated and will be removed from pandas in a future version. Use pandas.Index with the appropriate dtype instead.
pd.Int64Index,
<IPython.core.display.Image object>
```
2 Likes
Created a geodataframe from a saved shapefile:
gdf_poly = gpd.read_file(filename='shapefile_poly')
Then plotted with PyGMT:
fig.plot(data=gdf_poly)