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 mkdocs/docs/geospatial.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

## Data Representation
Expand Down
16 changes: 8 additions & 8 deletions pyiceberg/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ class GeometryType(PrimitiveType):
>>> GeometryType("EPSG:4326")
GeometryType(crs='EPSG:4326')
>>> str(GeometryType("EPSG:4326"))
"geometry('EPSG:4326')"
'geometry(EPSG:4326)'
"""

root: str = Field(default=DEFAULT_GEOMETRY_CRS)
Expand All @@ -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})"

@property
def crs(self) -> str:
Expand All @@ -1035,7 +1035,7 @@ def __str__(self) -> str:
"""Return the string representation."""
if self.crs == DEFAULT_GEOMETRY_CRS:
return "geometry"
return f"geometry('{self.crs}')"
return f"geometry({self.crs})"

def __hash__(self) -> int:
"""Return the hash of the CRS."""
Expand Down Expand Up @@ -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)'
"""

root: tuple[str, str] = Field(default=(DEFAULT_GEOGRAPHY_CRS, DEFAULT_GEOGRAPHY_ALGORITHM))
Expand All @@ -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})"

@property
def crs(self) -> str:
Expand All @@ -1114,8 +1114,8 @@ def __str__(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})"

def __hash__(self) -> int:
"""Return the hash of the tuple."""
Expand Down
17 changes: 11 additions & 6 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ def test_geometry_type_custom_crs() -> None:
"""Test GeometryType with custom CRS."""
type_var = GeometryType("EPSG:4326")
assert type_var.crs == "EPSG:4326"
assert str(type_var) == "geometry('EPSG:4326')"
assert str(type_var) == "geometry(EPSG:4326)"
assert repr(type_var) == "GeometryType(crs='EPSG:4326')"


Expand All @@ -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")


def test_geometry_type_deserialization() -> None:
Expand Down Expand Up @@ -847,7 +848,7 @@ def test_geography_type_custom_crs() -> None:
type_var = GeographyType("EPSG:4326")
assert type_var.crs == "EPSG:4326"
assert type_var.algorithm == DEFAULT_GEOGRAPHY_ALGORITHM
assert str(type_var) == "geography('EPSG:4326')"
assert str(type_var) == "geography(EPSG:4326)"
assert repr(type_var) == "GeographyType(crs='EPSG:4326')"


Expand All @@ -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')"


Expand All @@ -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"
)


def test_geography_type_deserialization() -> None:
Expand Down
Loading