Fokko commented on code in PR #4482:
URL: https://github.com/apache/iceberg-python/pull/4482#discussion_r4741837430
##########
mkdocs/docs/geospatial.md:
##########
@@ -67,8 +67,8 @@ NestedField(1, "point", "geometry", required=True)
NestedField(2, "region", "geography", required=True)
# With parameters
-NestedField(3, "location", "geometry('EPSG:4326')", required=True)
-NestedField(4, "boundary", "geography('EPSG:4326', 'planar')", required=True)
+NestedField(3, "location", "geometry(EPSG:4326)", required=True)
+NestedField(4, "boundary", "geography(EPSG:4326, planar)", required=True)
Review Comment:
Same as the docstring: `planar` isn't a spec-valid geography algorithm. The
`GeographyType("EPSG:4326", "planar")` example further up (line 57) needs the
same change.
```suggestion
NestedField(4, "boundary", "geography(EPSG:4326, spherical)", required=True)
```
##########
pyiceberg/types.py:
##########
@@ -1018,7 +1018,7 @@ def ser_model(self) -> str:
"""Serialize the model to a string."""
if self.crs == DEFAULT_GEOMETRY_CRS:
return "geometry"
- return f"geometry('{self.crs}')"
+ return f"geometry({self.crs})"
Review Comment:
The spec's type serialization table lists `"geometry(<C>)"` as the canonical
form ("The schema JSON type strings in this table are the canonical serialized
forms"). Java also always writes the CRS, including the default
(`String.format("%s(%s)", NAME, crs())`). Can we drop the default branch so
`GeometryType()` serializes as `geometry(OGC:CRS84)`?
```suggestion
return f"geometry({self.crs})"
```
Same for `__str__` below; Java uses a single `toString()` for both.
##########
pyiceberg/types.py:
##########
@@ -1088,8 +1088,8 @@ def ser_model(self) -> str:
if self.crs == DEFAULT_GEOGRAPHY_CRS and self.algorithm ==
DEFAULT_GEOGRAPHY_ALGORITHM:
return "geography"
if self.algorithm == DEFAULT_GEOGRAPHY_ALGORITHM:
- return f"geography('{self.crs}')"
- return f"geography('{self.crs}', '{self.algorithm}')"
+ return f"geography({self.crs})"
+ return f"geography({self.crs}, {self.algorithm})"
Review Comment:
Same here: the canonical form is `"geography(<C>, <A>)"`, and Java always
writes both parameters (`String.format("%s(%s, %s)", NAME, crs(),
algorithm())`), so the default becomes `geography(OGC:CRS84, spherical)`.
```suggestion
return f"geography({self.crs}, {self.algorithm})"
```
And the same for `__str__`.
##########
pyiceberg/types.py:
##########
@@ -1074,7 +1074,7 @@ class GeographyType(PrimitiveType):
>>> GeographyType("EPSG:4326", "planar")
GeographyType(crs='EPSG:4326', algorithm='planar')
>>> str(GeographyType("EPSG:4326", "planar"))
- "geography('EPSG:4326', 'planar')"
+ 'geography(EPSG:4326, planar)'
Review Comment:
`planar` isn't a valid edge-interpolation algorithm for `geography`. The
spec only allows `spherical`, `vincenty`, `thomas`, `andoyer` and `karney`
(planar edges are what `geometry` uses). Java's
`EdgeAlgorithm.fromName("planar")` throws, so Java can't load a table with this
type. Can we use `spherical` here?
```suggestion
>>> GeographyType("EPSG:4326", "spherical")
GeographyType(crs='EPSG:4326')
>>> str(GeographyType("EPSG:4326", "spherical"))
'geography(EPSG:4326, spherical)'
```
##########
tests/test_types.py:
##########
@@ -799,7 +799,8 @@ def test_geometry_type_pickle() -> None:
def test_geometry_type_serialization() -> None:
"""Test GeometryType JSON serialization."""
assert GeometryType().model_dump_json() == '"geometry"'
- assert GeometryType("EPSG:4326").model_dump_json() ==
"\"geometry('EPSG:4326')\""
+ assert GeometryType("EPSG:4326").model_dump_json() ==
'"geometry(EPSG:4326)"'
+ assert
GeometryType.model_validate_json(GeometryType("EPSG:4326").model_dump_json())
== GeometryType("EPSG:4326")
Review Comment:
With the canonical form, the default includes the CRS as well:
```suggestion
assert GeometryType().model_dump_json() == '"geometry(OGC:CRS84)"'
assert GeometryType("EPSG:4326").model_dump_json() ==
'"geometry(EPSG:4326)"'
assert
GeometryType.model_validate_json(GeometryType().model_dump_json()) ==
GeometryType()
assert
GeometryType.model_validate_json(GeometryType("EPSG:4326").model_dump_json())
== GeometryType("EPSG:4326")
```
If `__str__` changes too, the `str()` asserts in
`test_geometry_type_default` and `test_geography_type_default` need updating.
##########
tests/test_types.py:
##########
@@ -879,8 +880,12 @@ def test_geography_type_pickle() -> None:
def test_geography_type_serialization() -> None:
"""Test GeographyType JSON serialization."""
assert GeographyType().model_dump_json() == '"geography"'
- assert GeographyType("EPSG:4326").model_dump_json() ==
"\"geography('EPSG:4326')\""
- assert GeographyType("EPSG:4326", "planar").model_dump_json() ==
"\"geography('EPSG:4326', 'planar')\""
+ assert GeographyType("EPSG:4326").model_dump_json() ==
'"geography(EPSG:4326)"'
+ assert GeographyType("EPSG:4326", "planar").model_dump_json() ==
'"geography(EPSG:4326, planar)"'
+ assert
GeographyType.model_validate_json(GeographyType("EPSG:4326").model_dump_json())
== GeographyType("EPSG:4326")
+ assert GeographyType.model_validate_json(GeographyType("EPSG:4326",
"planar").model_dump_json()) == GeographyType(
+ "EPSG:4326", "planar"
+ )
Review Comment:
```suggestion
assert GeographyType().model_dump_json() == '"geography(OGC:CRS84,
spherical)"'
assert GeographyType("EPSG:4326").model_dump_json() ==
'"geography(EPSG:4326, spherical)"'
assert GeographyType("EPSG:4326", "karney").model_dump_json() ==
'"geography(EPSG:4326, karney)"'
assert
GeographyType.model_validate_json(GeographyType().model_dump_json()) ==
GeographyType()
assert
GeographyType.model_validate_json(GeographyType("EPSG:4326").model_dump_json())
== GeographyType("EPSG:4326")
assert GeographyType.model_validate_json(GeographyType("EPSG:4326",
"karney").model_dump_json()) == GeographyType(
"EPSG:4326", "karney"
)
```
##########
tests/test_types.py:
##########
@@ -856,7 +857,7 @@ def test_geography_type_custom_crs_and_algorithm() -> None:
type_var = GeographyType("EPSG:4326", "planar")
assert type_var.crs == "EPSG:4326"
assert type_var.algorithm == "planar"
- assert str(type_var) == "geography('EPSG:4326', 'planar')"
+ assert str(type_var) == "geography(EPSG:4326, planar)"
assert repr(type_var) == "GeographyType(crs='EPSG:4326',
algorithm='planar')"
Review Comment:
`planar` isn't spec-valid here either. `spherical` is the default, so to
keep covering a non-default algorithm this needs another valid value, e.g.
`karney`. The other `planar` uses in this file (the equality, pickle, singleton
and `NestedField` tests) need the same change.
```suggestion
type_var = GeographyType("EPSG:4326", "karney")
assert type_var.crs == "EPSG:4326"
assert type_var.algorithm == "karney"
assert str(type_var) == "geography(EPSG:4326, karney)"
assert repr(type_var) == "GeographyType(crs='EPSG:4326',
algorithm='karney')"
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]