-
Notifications
You must be signed in to change notification settings - Fork 901
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
Support orient
keyword in to_json
#3187
Comments
Thanks @paddymul for opening this issue. I wouldn't say this is a bug per se, but a mismatch of expectations. In the geospatial world the standard json representation of features is GeoJson - which specifies a specific layout for storing features separate to geometry alongside storing spatial metadata like a CRS (coordinate reference system). (For instance compare the output of In principle I think we would be open to supporting other orientations, so long as that does not lead to confusion about what is a generic interoperable geojson format and what is a pandas specific format. It'd be good for other maintainers to weight in, but my initial proposal to support this would be to introduce an |
orient
like pandas doesorient
keyword in to_json
FWIW I was able to get a regular pandas dataframe with the following code: pd_df = pd.DataFrame(dict(zip(df.columns, df.to_numpy().T))) Then I serialize via existing pandas methods. I no longer need geopandas to change the behavior of to_json, but I figure this code could be useful for others who stumble across this problem. |
I haven't compared the performance, but I think a slightly clearer way to express this would be |
[X ] I have checked that this issue has not already been reported.
[X ] 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
Problem description
I have a table library that supports pandas. I expected to be able to serialize a GeoDataFrame with the same serializer methods, but
to_json
doesn't supportorient
at all.I understand adding extra arguments for geo specific features, but I would expect pandas default arguments to work.
Expected Output
given that pandas of
outputs as
I would expect the following GeoPandas to output as
to output as
Output of
geopandas.show_versions()
SYSTEM INFO
python : 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
executable : /usr/bin/python3
machine : Linux-6.1.58+-x86_64-with-glibc2.35
GEOS, GDAL, PROJ INFO
GEOS : 3.11.2
GEOS lib : None
GDAL : 3.6.4
GDAL data dir: /usr/local/lib/python3.10/dist-packages/fiona/gdal_data
PROJ : 9.3.0
PROJ data dir: /usr/local/lib/python3.10/dist-packages/pyproj/proj_dir/share/proj
PYTHON DEPENDENCIES
geopandas : 0.13.2
numpy : 1.25.2
pandas : 1.5.3
pyproj : 3.6.1
shapely : 2.0.2
fiona : 1.9.5
geoalchemy2: None
geopy : 2.3.0
matplotlib : 3.7.1
mapclassify: None
pygeos : None
pyogrio : None
psycopg2 : 2.9.9 (dt dec pq3 ext lo64)
pyarrow : 10.0.1
rtree : None
The text was updated successfully, but these errors were encountered: