Skip to content

Extract the pivot and unit-conversion blocks out of object_transformer - #331

Merged
amc-corey-cox merged 7 commits into
mainfrom
extract-pivot-units
Aug 25, 2026
Merged

amc-corey-cox merged 7 commits into
mainfrom
extract-pivot-units

Conversation

@amc-corey-cox

Copy link
Copy Markdown
Contributor

Closes #304. Pure move — no new abstraction, no behaviour change.

object_transformer.py drops from 1558 to 1246 lines.

Pivot / EAV → transformer/pivot.py

Five functions (perform_pivot_operation, _perform_unmelt, _unmelt_single_record, _unmelt_collection, perform_melt), reached from two call sites and calling nothing else in the class.

An AST pass over the block confirmed the issue's claim about instance state, and it was cleaner than described — only _unmelt_single_record and perform_melt touched self at all, both solely for target_schemaview, which is now an explicit parameter threaded through the two callers.

Unit conversion → functions/unit_conversion.py

perform_unit_conversion lands next to convert_units and UnitSystem, which it already depended on.

It referenced zero instance state — everything came through DerivationContext. But that type is defined in object_transformer, which imports this module, so keeping the parameter would have made the import circular. It now takes the three fields it actually used (source_obj, sv, source_type) directly, which is what the issue proposed by "taking the schemaview explicitly". Verified there's no cycle by importing both modules standalone.

On the #298 overlap

The issue flagged that the mock tests drove the private _perform_unit_conversion directly, so whichever landed second had to account for the other. #323 landed first and replaced them with end-to-end tests through map_object — which is why this extraction needed no test changes at all. Had the mocks still been in place, all seven would have broken on a refactor that changes no behaviour. Confirmed nothing outside the class referenced any of the six moved methods.

Verification

1102 passed, 4 skipped, 1 xfailed — identical to main, since the existing pivot (9) and unit-conversion (7) tests already exercise this code end-to-end. ruff and format clean.

Both were self-contained subsystems reached from three call sites and calling
nothing else in the class. object_transformer.py drops from 1558 to 1246 lines.

The pivot group (MELT/UNMELT, 5 functions) moves to transformer/pivot.py. Only
two of them touched instance state, and only target_schemaview, which they now
take explicitly.

_perform_unit_conversion moves to functions/unit_conversion.py, next to
convert_units and UnitSystem, which it already depended on. It referenced no
instance state at all — it took everything through DerivationContext — so it
takes the three fields it used (source row, schemaview, source type) as
parameters instead. Depending on DerivationContext would have been circular,
since object_transformer imports this module.

No behaviour change: 1102 passed, 4 skipped, 1 xfailed, unchanged.

Closes #304
Copilot AI lite review requested due to automatic review settings August 14, 2026 16:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restructures ObjectTransformer by extracting the self-contained pivot (MELT/UNMELT) and unit-conversion logic into dedicated modules, reducing object_transformer.py size and keeping related functionality colocated with its natural neighbors.

Changes:

  • Moved pivot/EAV reshaping functions into src/linkml_map/transformer/pivot.py and updated call sites to pass target_schemaview explicitly.
  • Moved unit-conversion execution logic into src/linkml_map/functions/unit_conversion.py as perform_unit_conversion, avoiding DerivationContext to prevent circular imports.
  • Updated ObjectTransformer to call the new module-level functions and removed the in-class implementations.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/linkml_map/transformer/pivot.py Introduces module-level pivot helpers (perform_pivot_operation, perform_melt, and unmelt helpers) extracted from ObjectTransformer.
src/linkml_map/transformer/object_transformer.py Rewires pivot and unit-conversion call sites to the new module functions and removes the extracted method blocks.
src/linkml_map/functions/unit_conversion.py Adds perform_unit_conversion alongside existing unit utilities so conversion execution lives with convert_units/UnitSystem.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/linkml_map/transformer/pivot.py Outdated
The extracted pivot functions defaulted target_sv to None, so a caller that
forgot it would silently melt every non-ID slot instead of inferring from
unmelt_to_class. Make it required.

class_deriv, sv and source_type were never read by the unmelt path, and
perform_melt ignored slot_derivation -- which is why perform_pivot_operation
could pass a ClassDerivation into it without anything noticing.
Copilot AI review requested due to automatic review settings August 25, 2026 15:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI review requested due to automatic review settings August 25, 2026 15:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI review requested due to automatic review settings August 25, 2026 15:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 25, 2026 16:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread src/linkml_map/transformer/pivot.py Outdated
Copilot AI review requested due to automatic review settings August 25, 2026 16:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@amc-corey-cox
amc-corey-cox merged commit a62221f into main Aug 25, 2026
10 checks passed
@amc-corey-cox
amc-corey-cox deleted the extract-pivot-units branch August 25, 2026 17:01
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.

Extract pivot and unit-conversion blocks out of object_transformer.py

2 participants