-
Notifications
You must be signed in to change notification settings - Fork 37
Enforce type geometry properties #94
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
Conversation
@@ -15,7 +15,7 @@ jobs: | |||
runs-on: ubuntu-latest | |||
strategy: | |||
matrix: | |||
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] | |||
python-version: ['3.8', '3.9', '3.10', '3.11'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's deprecate python 3.7:
- because it's old
- because it doesn't support Literal by default
geojson_pydantic/features.py
Outdated
properties: Optional[Props] = None | ||
type: Literal["Feature"] | ||
geometry: Union[Geom, None] = Field(...) | ||
properties: Props = Field(...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TO BE DISCUSSED
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A Feature object has a member with the name "properties". The value of the properties member is an object (any JSON object or a JSON null value).
Probably should be: properties: Union[Props, None] = Field(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right so we should accept properties=None
@@ -44,23 +46,22 @@ def __geo_interface__(self) -> Dict[str, Any]: | |||
"geometry": self.geometry.__geo_interface__ | |||
if self.geometry is not None | |||
else None, | |||
"properties": self.properties, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
properties should always be set to at least {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically GeoJSON can have null properties. But geo_interface says
properties (optional) - A mapping of feature properties ...
So, I would say leave this how it was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the issue then is that you wouldn't be able to do Feature(**Feature(type="Feature", geometry=None, properties=None).__geo_interface__)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 https://github.com/jazzband/geojson/blob/main/geojson/feature.py#L31 always default to {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: we already allow geometry
to be None
in the geo_interface while the spec says it should be a mapping 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is an interesting one. Not being able to put it back into itself is problematic. And None
becomes {}
in __geo_interface__
that would mean properties
would change when fed back in. The least bad thing might be a pre validator that converts None
to dict()
?
Note: we already allow geometry to be None in the geo_interface while the spec says it should be a mapping 🤷
The current way won't add the Edit: Mixed up properties and geometry in my head at some point.geometry
key to the dict unless it is truthy. So it would never be None
, it just wouldn't exist at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current way won't add the geometry key to the dict unless it is truthy. So it would never be None, it just wouldn't exist at all.
Feature(type="Feature", geometry=None, properties=None).__geo_interface__
>> {'type': 'Feature', 'geometry': None, 'properties': None}
we do add geometry: None
in the current implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vincentsarago Sorry, I had started to edit that comment and apparently never saved it. Got lost in the 12 tabs open looking at too many parts at the same time.
Based on a strict reading geometry may be wrong. However jazzband/geojson is just returning self as the __geo_interface__
so geometry could be None
there as well.
Which actually seems like a good idea, its supposed to be modeled after geojson, so just return self.dict()
. Don't worry about picking fields like it currently does.
geojson_pydantic/features.py
Outdated
properties: Optional[Props] = None | ||
type: Literal["Feature"] | ||
geometry: Union[Geom, None] = Field(...) | ||
properties: Props = Field(...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A Feature object has a member with the name "properties". The value of the properties member is an object (any JSON object or a JSON null value).
Probably should be: properties: Union[Props, None] = Field(...)
@@ -44,23 +46,22 @@ def __geo_interface__(self) -> Dict[str, Any]: | |||
"geometry": self.geometry.__geo_interface__ | |||
if self.geometry is not None | |||
else None, | |||
"properties": self.properties, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically GeoJSON can have null properties. But geo_interface says
properties (optional) - A mapping of feature properties ...
So, I would say leave this how it was.
@eseglem are we happy with the changes proposed here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think __geo_interface__
may be worth additional discussion but that is outside the scope of this PR. Looks good to me.
@geospatial-jeff do you have opinions? the TLDR of this pr is:
Those are quite Another change that will be discussed in another Issue is the fact that we don't follow the geo_interface_ specifiation to the letter because we set values to |
I agree with these changes, it better matches the spec which is what I care about. Keeping in mind that this library was spun out of |
closes #92