Skip to content

feat: differentiate dyn_display and dyn_debug for extension types#262

Open
thomaschi78 wants to merge 3 commits into
pola-rs:mainfrom
thomaschi78:feat/extension-type-display
Open

feat: differentiate dyn_display and dyn_debug for extension types#262
thomaschi78 wants to merge 3 commits into
pola-rs:mainfrom
thomaschi78:feat/extension-type-display

Conversation

@thomaschi78

Copy link
Copy Markdown

Closes #259.

What this changes

dyn_display and dyn_debug previously produced identical output (both used {:?}). This PR differentiates them following the Polars convention documented in ExtensionTypeImpl:

dyn_display — short string, lowercase: str, datetime[ms]
dyn_debug — verbose TitleCase: String, Decimal(10, 2)

dyn_display — new format

Type Example output
Point / LineString / Polygon / MultiPoint / MultiLineString / MultiPolygon / GeometryCollection point[xy, separated], linestring[xyz, interleaved], …
Geometry geometry[interleaved]
Box box[xyzm]
Wkb wkb
Wkt wkt
Invalid (any type) InvalidExtensionType(<message>)

dyn_debug — unchanged

Keeps {:?} which produces the full derived Debug representation, e.g.:

PointType { coord_type: Separated, dim: XY, metadata: Metadata { crs: Crs { crs: None, crs_type: None }, edges: None } }

Implementation

  • Adds a crate-private ShortDisplay trait with a short_display() -> String method.
  • A helper macro impl_short_display_dim_coord! handles the 7 types that have both dimension() and coord_type().
  • The 4 remaining types (GeometryType, BoxType, WkbType, WktType) are implemented individually.
  • format_inner (shared helper from Allow extension types to be fallible #260) is removed; dyn_display and dyn_debug now have distinct match arms.
  • 8 new tests pin the exact display format and assert dyn_display != dyn_debug for valid types.

Store `Result<T, String>` instead of `T` in each GeoArrow wrapper type so
that an incompatible storage type passed to `GeoArrowExtensionTypeFactory`
is captured as an error rather than causing a panic. The `invalid()`
constructor and `TryFrom` conversion surface the error to callers; `name()`
always returns the correct constant regardless of validity.

Replaces the infallible `From<WrapperType> for geoarrow_schema::T` with
`TryFrom`, extracts a shared `format_inner` helper in the macro to avoid
duplicating `dyn_display`/`dyn_debug` logic, and adds 22 tests covering
the valid and error paths across constructors, traits, and the factory.
…la-rs#259)

dyn_display now produces a short lowercase string following Polars
convention (e.g. point[xy, separated], geometry[interleaved], box[xyzm],
wkb) via a ShortDisplay trait implemented for each geoarrow_schema type.
dyn_debug keeps the verbose {:#?} output (e.g. PointType { coord_type:
Separated, dim: XY, metadata: ... }) which is more useful for debugging.

Adds 8 new tests pinning the exact display format for point, geometry,
box, wkb, and wkt, and asserting that display and debug differ for valid
types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve text display of extension types

1 participant