Skip to content

Honor source extension coercions - #9418

Open
connortsui20 wants to merge 1 commit into
developfrom
ct/extension-coerce-to
Open

Honor source extension coercions#9418
connortsui20 wants to merge 1 commit into
developfrom
ct/extension-coerce-to

Conversation

@connortsui20

@connortsui20 connortsui20 commented Aug 14, 2026

Copy link
Copy Markdown
Member

Rationale for this change

DType::can_coerce_from previously asked only the target extension whether it accepted a source. This left ExtVTable::can_coerce_to unused and prevented source-owned refinement types from declaring lossless widening conversions.

What changes are included in this PR?

Extension coercion now checks target.can_coerce_from(source) first, then source.can_coerce_to(target). The coercion APIs and existing extension implementations now use source and target instead of ambiguous names such as other and ext_dtype. Direct ExtensionArray casts only rewrap storage when the source opts in because target-side coercions can require transforming values.

What APIs are changed? Are there any user-facing changes?

Extension authors can implement ExtVTable::can_coerce_to(source, target) for storage-compatible widening conversions. Existing extensions retain their target-side behavior.

@codspeed-hq

codspeed-hq Bot commented Aug 14, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 13.25%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚡ 1 improved benchmark
✅ 1999 untouched benchmarks
⏩ 89 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime words_gather_scalar[65536] 9.4 µs 8.3 µs +13.25%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ct/extension-coerce-to (ec1dddb) with develop (b363fb7)

Open in CodSpeed

Footnotes

  1. 89 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@connortsui20
connortsui20 force-pushed the ct/extension-coerce-to branch 2 times, most recently from f8db2db to f7d3820 Compare August 14, 2026 20:19
Comment on lines +31 to +33
let target_storage = array
.storage_array()
.cast(target_ext_dtype.storage_dtype().clone())?;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@gatesn I think this is fine? only because we said above that it can be coerced

@connortsui20
connortsui20 force-pushed the ct/extension-coerce-to branch from f7d3820 to a30d702 Compare August 14, 2026 20:35
Comment on lines +285 to +286
if let DType::Extension(source_ext) = source {
return source_ext.can_coerce_to(self);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is the only logical change

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
@connortsui20
connortsui20 force-pushed the ct/extension-coerce-to branch from a30d702 to ec1dddb Compare August 14, 2026 20:40
@connortsui20
connortsui20 marked this pull request as ready for review August 14, 2026 20:41
@connortsui20 connortsui20 added changelog/chore A trivial change and removed changelog/feature A new feature labels Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/chore A trivial change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant