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: pandas 2.2.0 changes GeoDataFrame.from_records() behavior #3152

Open
2 of 3 tasks
robertschweizer opened this issue Jan 22, 2024 · 2 comments
Open
2 of 3 tasks

Comments

@robertschweizer
Copy link

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of geopandas.

  • (optional) I have confirmed this bug exists on the main branch of geopandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

from geopandas import GeoDataFrame
from shapely import box

gdf = GeoDataFrame.from_records([{"value": 12, "geometry": box(0,0,1,1)}])
gdf.geometry

Problem description

The above code sample works with pandas 2.1.4, but with pandas 2.2.0 I get:

AttributeError: You are calling a geospatial method on the GeoDataFrame, but the active geometry column to use has not been set.
There are no existing columns with geometry data type. You can add a geometry column as the active geometry column with df.set_geometry.

Expected Output

There should be no exception without prior deprecation warnings.

Output of geopandas.show_versions()

SYSTEM INFO

python : 3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:12:31) [Clang 14.0.6 ]
executable : /opt/homebrew/Caskroom/miniforge/base/bin/python3.10
machine : macOS-14.2.1-arm64-arm-64bit

GEOS, GDAL, PROJ INFO

GEOS : 3.11.2
GEOS lib : None
GDAL : 3.6.4
GDAL data dir: /opt/homebrew/Caskroom/miniforge/base/lib/python3.10/site-packages/fiona/gdal_data
PROJ : 9.2.1
PROJ data dir: /opt/homebrew/Caskroom/miniforge/base/lib/python3.10/site-packages/pyproj/proj_dir/share/proj

PYTHON DEPENDENCIES

geopandas : 0.14.2
numpy : 1.23.5
pandas : 2.2.0
pyproj : 3.6.0
shapely : 2.0.2
fiona : 1.9.4.post1
geoalchemy2: None
geopy : None
matplotlib : 3.7.1
mapclassify: None
pygeos : None
pyogrio : None
psycopg2 : None
pyarrow : None
rtree : 1.0.1

@jorisvandenbossche
Copy link
Member

@robertschweizer thanks for the report!

This seems to be a regression on the pandas side in its from_records method in pandas 2.2 (I will open a report upstream). We could maybe fix it on our side short term by overriding from_records.

It looks a bit duplicative, but as a quick workaround to let your code work as before, you can pass the result once more to GeoDataFrame(..):

gdf = GeoDataFrame(GeoDataFrame.from_records([{"value": 12, "geometry": box(0,0,1,1)}]))

@jorisvandenbossche
Copy link
Member

Opened pandas-dev/pandas#57008 on the pandas side.

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

No branches or pull requests

3 participants