Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pygmt/helpers/tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ def tempfile_from_geojson(geojson):
import geopandas as gpd # noqa: PLC0415

Path(tmpfile.name).unlink() # Ensure file is deleted first
ogrgmt_kwargs = {"filename": tmpfile.name, "driver": "OGR_GMT", "mode": "w"}
ogrgmt_kwargs = {
"filename": tmpfile.name,
"driver": "OGR_GMT",
"mode": "w",
"encoding": "UTF-8", # Necessary for non-ASCII support on Windows.
}
try:
# OGR_GMT only supports 32-bit integers. We need to map int/int64
# types to int32/float types depending on if the column has an
Expand Down
28 changes: 28 additions & 0 deletions pygmt/tests/test_geopandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,31 @@ def test_geopandas_data_kind_shapely():
"""
polygon = shapely.geometry.Polygon([(20, 10), (23, 10), (23, 14), (20, 14)])
assert data_kind(data=polygon) == "geojson"


def test_geopandas_nonascii():
"""
Test geopandas.GeoDataFrame with non-ASCII characters.

The tempfile_from_geojson function writes the GeoDataFrame to a temporary OGR_GMT
file, which doesn't work properly if UTF-8 is not the default encoding (e.g.,
Windows).
"""
geom = shapely.geometry.Polygon(
[
(0, 1),
(0, 2),
(1, 1),
(1, 3),
]
)
gdf = gpd.GeoDataFrame(
{
"name_ascii": ["Fiji"],
"name_utf8": ["فيجي"], # Arabic
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can confirm that this is Fiji in Arabic 😆

},
geometry=[geom],
crs="EPSG:4326",
)
output = info(gdf, per_column=True)
npt.assert_allclose(actual=output, desired=[0.0, 1.0, 1.0, 3.0])