Skip to content

[arrow-pyarrow]: restore nicer pyarrow-arrow error message - #9639

Merged
alamb merged 2 commits into
apache:mainfrom
alamb:fix/pr9594-arrow-c-array-error
Apr 1, 2026
Merged

[arrow-pyarrow]: restore nicer pyarrow-arrow error message#9639
alamb merged 2 commits into
apache:mainfrom
alamb:fix/pr9594-arrow-c-array-error

Conversation

@alamb

@alamb alamb commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

@kylebarron says #9594 (comment):

fwiw previously there was a nice user-facing error here, while now the error generated from extract will be much more obtuse. Ideally this exception will never be raised except if the producer doesn't follow the spec correctly.

What changes are included in this PR?

Restore the nice error

Are these changes tested?

yes, added a test

Are there any user-facing changes?

@alamb
alamb marked this pull request as ready for review March 31, 2026 20:44
@alamb alamb changed the title [arrow-pyarrow]: restore __arrow_c_array__ tuple error [arrow-pyarrow]: restore nicer pyarrow-arrow error message Apr 1, 2026
@alamb
alamb requested a review from kylebarron April 1, 2026 10:54

@Tpt Tpt 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.

Thank you! Some minor improvement idea.

If you want I can prepare a new MR that build a similar nice error for each extraction of the crate while propagating the original error.

Comment thread arrow-pyarrow/src/lib.rs
) -> PyResult<(Bound<'py, PyCapsule>, Bound<'py, PyCapsule>)> {
let tuple = value.call_method0("__arrow_c_array__")?;

if !tuple.is_instance_of::<PyTuple>() {

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.

if I am not mistaken .extract() will fail if tuple is not a tuple, returning the exact same error. I think we can drop this case.

Comment thread arrow-pyarrow/src/lib.rs
));
}

tuple.extract().map_err(|_| {

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.

tip if you want to propagate the original error as a "cause" to get a sightly nicer backtrace:

Suggested change
tuple.extract().map_err(|_| {
tuple.extract().map_err(|e| {
let err = PyTypeError::new_err(
"Expected __arrow_c_array__ to return a tuple of (schema, array) capsules.",
);
err.set_cause(value.py(), Some(e));
err

@alamb

alamb commented Apr 1, 2026

Copy link
Copy Markdown
Contributor Author

Thank you! Some minor improvement idea.

If you want I can prepare a new MR that build a similar nice error for each extraction of the crate while propagating the original error.

That would be great -- thank you 🙏

@alamb alamb closed this Apr 1, 2026
@alamb

alamb commented Apr 1, 2026

Copy link
Copy Markdown
Contributor Author

Closing this one in favor of the work from @Tpt

@alamb alamb reopened this Apr 1, 2026
@alamb

alamb commented Apr 1, 2026

Copy link
Copy Markdown
Contributor Author

Actually, since this one is approved, I'll merge it in and then @Tpt can you prepare a follow on PR to improve the messages further?

@alamb
alamb merged commit 652c950 into apache:main Apr 1, 2026
25 checks passed
Rich-T-kid pushed a commit to Rich-T-kid/arrow-rs that referenced this pull request Jun 2, 2026
# Which issue does this PR close?

- Follow on to apache#9594

# Rationale for this change


@kylebarron says
apache#9594 (comment):

> fwiw previously there was a nice user-facing error here, while now the
error generated from extract will be much more obtuse. Ideally this
exception will never be raised except if the producer doesn't follow the
spec correctly.

# What changes are included in this PR?
Restore the nice error

# Are these changes tested?

yes, added a test

# Are there any user-facing changes?

<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.

If there are any breaking changes to public APIs, please call them out.
-->
alamb pushed a commit that referenced this pull request Jun 22, 2026
Remove validate_pycapsule: pointer_checked already raises an exception
if the capsule type is wrong, and we wrap it into a nicer error

Also relies on a trait to associate types with their capsules names

Because we wrap the exception (equivalent of `raise X from Y`), the
original exception is still there

Follow up of  #9639 #9594
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.

3 participants