From 64f374ee3a5d86a3529abe774318e3d6fcc4e5dc Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Tue, 25 Nov 2025 09:06:27 +0800 Subject: [PATCH 1/3] Add a test for geopandas with non-ASCII characters --- pygmt/tests/test_geopandas.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pygmt/tests/test_geopandas.py b/pygmt/tests/test_geopandas.py index a98f1d3a014..d7c689223e9 100644 --- a/pygmt/tests/test_geopandas.py +++ b/pygmt/tests/test_geopandas.py @@ -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 ORG_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 + }, + 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]) From 90ff2c9858a3feba2309e640adcb0fbe5f26f816 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Tue, 25 Nov 2025 09:32:57 +0800 Subject: [PATCH 2/3] Set encoding to UTF-8 --- pygmt/helpers/tempfile.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pygmt/helpers/tempfile.py b/pygmt/helpers/tempfile.py index 38f914b7f89..733f28d9d38 100644 --- a/pygmt/helpers/tempfile.py +++ b/pygmt/helpers/tempfile.py @@ -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 From 2f040feb9fd56c51117a9bbb4b4a77b81f185715 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Tue, 25 Nov 2025 11:46:21 +0800 Subject: [PATCH 3/3] Update pygmt/tests/test_geopandas.py [skip ci] Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- pygmt/tests/test_geopandas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygmt/tests/test_geopandas.py b/pygmt/tests/test_geopandas.py index d7c689223e9..982ca868785 100644 --- a/pygmt/tests/test_geopandas.py +++ b/pygmt/tests/test_geopandas.py @@ -266,7 +266,7 @@ def test_geopandas_nonascii(): """ Test geopandas.GeoDataFrame with non-ASCII characters. - The tempfile_from_geojson function writes the GeoDataFrame to a temporary ORG_GMT + 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). """