Repository navigation
fix(expressions): keep tabs inside string literals - #4001
Rodrigo-Palma wants to merge 1 commit into
Conversation
pyparsing expands tabs in the input before matching, so a tab inside a string
literal was rewritten into spaces, and the number of spaces depended on where
the literal sat in the expression: parse("a = 'x\ty'") and parse("ab = 'x\ty'")
returned different values for the same literal. A filter on a value containing
a tab silently matched nothing.
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that's incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions. |
|
@kevinjqliu friendly ping: since you touched the pyparsing setup in #3081, you may be the right reviewer. |
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that's incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions. |
|
Still relevant: on current |
Rationale for this change
parse()hands the expression straight to pyparsing, which expands tabs in the input before matching. A tab inside a string literal is therefore rewritten into spaces before the literal is ever read, and because the expansion runs over the whole expression, the number of spaces depends on where the literal happens to sit:Two filters written against the same stored value produce two different literals, and neither is the value the user asked for. A row whose column really contains a tab is never matched, and nothing reports an error:
row_filter="col = 'a\tb'"simply returns no rows.pyparsing exposes
parse_with_tabs()precisely for this, and it is set once on the top-level element rather than per call.Are these changes tested?
Yes, two tests in
tests/expressions/test_parser.py: one asserting that a tab survives the round trip, and one asserting that the same literal parses identically from two positions, which is the part that makes the corruption silent. Both fail onmainat0d58407and pass with the change.Ran locally:
make lint(ruff, ruff-format, mypy, pydocstyle, codespell, uv-lock) all green;tests/expressions584 passed,tests/table512 passed,tests/utils203 passed,tests/io/test_io.py30 passed. Not run here:tests/io/test_fsspec.py, which needs a moto server onlocalhost:9000, andtests/avro/test_decoder.py, whoseCythonBinaryDecodercases fail on a cleanmainin this checkout because the Cython extension is stale.Are there any user-facing changes?
Yes, in the sense that a filter over a string containing a tab now matches the rows it names. No public signature changes, and expressions without tabs parse exactly as before.