Skip to content

fix: apply segments= and pre= on PyArrow tables - #593

Merged
rich-iannone merged 3 commits into
posit-dev:mainfrom
tushar-mahalya:fix/pyarrow-segments-pre
Nov 25, 2026
Merged

rich-iannone merged 3 commits into
posit-dev:mainfrom
tushar-mahalya:fix/pyarrow-segments-pre

Conversation

@tushar-mahalya

@tushar-mahalya tushar-mahalya commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix for #592. On a PyArrow table, segments=("col", value) validates every segment against all rows, because _apply_segments() doesn't recognise PyArrow and hands the table back unfiltered. segments="col" fails in _seg_expr_from_string() with "Unsupported table type", and any pre= ends in an eval error, since interrogate() does set(tbl.columns) and on PyArrow that's a list of ChunkedArrays.

So this adds "pyarrow" to the Narwhals branch in both segment helpers, and gets the column names for the pre= bookkeeping through the existing _get_column_names_safe(). PyArrow isn't in the "Supported Input Table Types" docstrings, but since PyArrow fixes like #586 went in recently I assumed it's meant to work.

The new tests run the same segment steps on Polars, pandas and PyArrow and compare the counts, plus a pre= test on PyArrow. The PyArrow cases fail without the change.

Related GitHub Issues and PRs

Checklist

  • I understand and agree to the Code of Conduct.
  • I have followed the Style Guide for Python Code as best as possible for the submitted code.
  • I have added pytest unit tests for any new functionality.

tushar-mahalya and others added 3 commits November 26, 2026 02:02
_apply_segments() didn't recognise PyArrow tables and returned them unfiltered, so each segment was validated against every row. A string segments= raised a ValueError, and pre= marked the step as an evaluation error because the PyArrow Table.columns attribute holds arrays rather than column names.

@rich-iannone rich-iannone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@rich-iannone
rich-iannone merged commit 2f9599b into posit-dev:main Nov 25, 2026
12 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.

segments= and pre= give wrong results or errors on PyArrow tables

2 participants