@@ -1153,16 +1153,34 @@ def test_write_dataframe_index(tmp_path, naturalearth_lowres, use_arrow):
1153
1153
1154
1154
1155
1155
@pytest .mark .parametrize ("ext" , [ext for ext in ALL_EXTS if ext not in ".geojsonl" ])
1156
+ @pytest .mark .parametrize (
1157
+ "columns, dtype" ,
1158
+ [
1159
+ ([], None ),
1160
+ (["col_int" ], np .int64 ),
1161
+ (["col_float" ], np .float64 ),
1162
+ (["col_object" ], object ),
1163
+ ],
1164
+ )
1156
1165
@pytest .mark .requires_arrow_write_api
1157
- def test_write_empty_dataframe (tmp_path , ext , use_arrow ):
1158
- expected = gp . GeoDataFrame ( geometry = [], crs = 4326 )
1166
+ def test_write_empty_dataframe (tmp_path , ext , columns , dtype , use_arrow ):
1167
+ """Test writing dataframe with no rows.
1159
1168
1169
+ With use_arrow, object type columns with no rows are converted to null type columns
1170
+ by pyarrow, but null columns are not supported by GDAL. Added to test fix for #513.
1171
+ """
1172
+ expected = gp .GeoDataFrame (geometry = [], columns = columns , dtype = dtype , crs = 4326 )
1160
1173
filename = tmp_path / f"test{ ext } "
1161
1174
write_dataframe (expected , filename , use_arrow = use_arrow )
1162
1175
1163
1176
assert filename .exists ()
1164
- df = read_dataframe (filename )
1165
- assert_geodataframe_equal (df , expected )
1177
+ df = read_dataframe (filename , use_arrow = use_arrow )
1178
+
1179
+ # Check result
1180
+ # For older pandas versions, the index is created as Object dtype but read as
1181
+ # RangeIndex, so don't check the index dtype in that case.
1182
+ check_index_type = True if PANDAS_GE_20 else False
1183
+ assert_geodataframe_equal (df , expected , check_index_type = check_index_type )
1166
1184
1167
1185
1168
1186
def test_write_empty_geometry (tmp_path ):
@@ -1182,6 +1200,24 @@ def test_write_empty_geometry(tmp_path):
1182
1200
assert_geodataframe_equal (df , expected )
1183
1201
1184
1202
1203
+ @pytest .mark .requires_arrow_write_api
1204
+ def test_write_None_string_column (tmp_path , use_arrow ):
1205
+ """Test pandas object columns with all None values.
1206
+
1207
+ With use_arrow, such columns are converted to null type columns by pyarrow, but null
1208
+ columns are not supported by GDAL. Added to test fix for #513.
1209
+ """
1210
+ gdf = gp .GeoDataFrame ({"object_col" : [None ]}, geometry = [Point (0 , 0 )], crs = 4326 )
1211
+ filename = tmp_path / "test.gpkg"
1212
+
1213
+ write_dataframe (gdf , filename , use_arrow = use_arrow )
1214
+ assert filename .exists ()
1215
+
1216
+ result_gdf = read_dataframe (filename , use_arrow = use_arrow )
1217
+ assert result_gdf .object_col .dtype == object
1218
+ assert_geodataframe_equal (result_gdf , gdf )
1219
+
1220
+
1185
1221
@pytest .mark .parametrize ("ext" , [".geojsonl" , ".geojsons" ])
1186
1222
@pytest .mark .requires_arrow_write_api
1187
1223
def test_write_read_empty_dataframe_unsupported (tmp_path , ext , use_arrow ):
0 commit comments