Skip to content

DOC: document late-binding behavior of Transformer serialization methods#1604

Open
madhavcodez wants to merge 1 commit into
pyproj4:mainfrom
madhavcodez:docs/transformer-late-binding-1549
Open

DOC: document late-binding behavior of Transformer serialization methods#1604
madhavcodez wants to merge 1 commit into
pyproj4:mainfrom
madhavcodez:docs/transformer-late-binding-1549

Conversation

@madhavcodez

Copy link
Copy Markdown

Summary

A Transformer built with Transformer.from_crs(...) is late-binding: PROJ does not select a concrete operation until transform() is called with coordinates. Until then to_json() and to_wkt() return None, and to_json_dict() raises TypeError: the JSON object must be str, bytes or bytearray, not NoneType (#1549). The docstrings did not mention this, so the None and the TypeError look like bugs.

Changes

  • Document the late-binding behavior in the to_json, to_wkt, and to_json_dict docstrings, including the two ways to obtain a serializable operation: call get_last_used_operation() after transform() (PROJ 9.1+), or build a TransformerGroup and serialize one of its candidate operations.
  • Note the asymmetry in this state: to_json / to_wkt return None while to_json_dict raises TypeError.
  • Qualify the Returns of to_json / to_wkt as str or None.
  • Add a docs/history.rst entry.

Docs only, no behavior change.

Closes #1549

Transformer.from_crs builds a PROJ late-binding transformer that defers
selecting a concrete transformation until transform() is called. Until then
to_wkt() and to_json() return None and to_json_dict() raises TypeError, none of
which the docstrings mentioned, so downstream code that trusted the documented
str/dict return crashed.

Add a Notes section to to_wkt, to_json, and to_json_dict describing the
late-binding case and the two workarounds (get_last_used_operation after
transform, or TransformerGroup), qualify the Returns of to_wkt/to_json to allow
None, and add a history entry.

Closes pyproj4#1549
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.

Transformer.to_json() returns None for valid CRS pair

1 participant