Skip to content

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

Merged
alamb merged 2 commits intoapache: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 intoapache:mainfrom
alamb:fix/pr9594-arrow-c-array-error

Conversation

@alamb
Copy link
Copy Markdown
Contributor

@alamb alamb commented Mar 31, 2026

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
Copy link
Copy Markdown
Contributor

@Tpt Tpt left a comment

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.

) -> 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.

));
}

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
Copy link
Copy Markdown
Contributor Author

alamb commented Apr 1, 2026

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
Copy link
Copy Markdown
Contributor Author

alamb commented Apr 1, 2026

Closing this one in favor of the work from @Tpt

@alamb alamb reopened this Apr 1, 2026
@alamb
Copy link
Copy Markdown
Contributor Author

alamb commented Apr 1, 2026

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
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