Skip to content
Open
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
4 changes: 2 additions & 2 deletions fiona/ogrext.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ cdef class OGRFeatureBuilder:
val_type = type(value)

if val_type in self.property_setter_cache:
setter = self.property_setter_cache[val_type]
setter = self.property_setter_cache[(val_type, schema_type)]
else:
for cls in val_type.mro():
fieldkey = (*FIELD_TYPES_MAP2[NAMED_FIELD_TYPES[schema_type]], cls.__name__)
Expand All @@ -773,7 +773,7 @@ cdef class OGRFeatureBuilder:
except KeyError:
continue
else:
self.property_setter_cache[val_type] = setter
self.property_setter_cache[(val_type, schema_type)] = setter
break
else:
log.warning("Skipping field because of invalid value: key=%r, value=%r", key, value)
Expand Down
30 changes: 30 additions & 0 deletions tests/test_bigint.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,33 @@ def test_issue691(tmpdir, dtype):
assert src.schema["properties"]["foo"] == "int:18"
first = next(iter(src))
assert first["properties"]["foo"] == 3694063472

def test_mixed_int_widths(tmpdir):
"""Demonstrate fix for #1501."""
Copy link
Author

Choose a reason for hiding this comment

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

I wasn't really sure where to put this test. I noticed it's also a problem for shapefiles and here seemed like an okay spot, but happy to move it.

schema = {"geometry": "Any", "properties": {"A": 'int32', "B":"int64"}}
with fiona.open(
str(tmpdir.join("test.shp")),
"w",
driver="Shapefile",
schema=schema,
crs="epsg:4326",
) as dst:
dst.write(
Feature.from_dict(
**{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": (-122.278015, 37.868995),
},
"properties": {"A": 3, "B": 3694063472},
}
)
)

with fiona.open(str(tmpdir.join("test.shp"))) as src:
assert src.schema["properties"]["A"] == "int32:9"
assert src.schema["properties"]["B"] == "int:18"
first = next(iter(src))
assert first["properties"]["A"] == 3
assert first["properties"]["B"] == 3694063472
24 changes: 24 additions & 0 deletions tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,3 +854,27 @@ class MyDate(datetime.date):
assert colxn.schema["properties"]["when"] == "date"
feat = next(colxn)
assert feat.properties["when"] == "2024-04-15"


def test_write_date_and_string(tmp_path):
"""Demonstrate fix for #1490."""

feat = Feature.from_dict(
{
"properties": {"date": "2022-09-01", "text":"n"},
"geometry": {"type": "Point", "coordinates": [0, 0]},
}
)
with fiona.open(
tmp_path / "test.gpkg",
"w",
driver="GPKG",
crs="EPSG:4326",
schema={"geometry": "Point", "properties": {"date": "date", "text": "str"}},
) as colxn:
colxn.writerecords([feat])

with fiona.open(tmp_path / "test.gpkg") as colxn:
assert colxn.schema["properties"]["date"] == "date"
feat = next(colxn)
assert feat.properties["date"] == "2022-09-01"