Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #279
Who hits this: Any
pairtools selectuser combining--remove-columnswith a filter condition (for example droppingread_len1,read_len2while filtering onmapq1/mapq2), or callingevaluate_stream/evaluate_dfwith customtype_castor conditions containing column names inside string literals or f-strings. #279Root cause
pairtools/cli/select.py):select_py()removed--remove-columnsfrom the header viaheaderops.set_columns(...)before callingheaderops.extract_column_names(header)to buildcolumn_namesforevaluate_stream(). Becauseevaluate_stream()reads the unmodified input rows, every column after a removed column was evaluated at the wrong index (e.g.,mapq1/mapq2silently readread_len1/read_len2values), and filtering on a removed column raisedNameError.TYPESmutation (pairtools/lib/select.py):evaluate_stream()calledTYPES.update(dict(type_cast))in place, leaking custom casts into laterevaluate_stream()/evaluate_df()calls in the same Python process.pairtools/lib/select.py):re.sub(r"\b%s\b" % col, ...)rewrote column names appearing inside string literals (e.g.readID == "mapq1"), attribute/keyword names, f-string debug expressions, and comprehension/lambda parameters.Changes
pairtools/cli/select.py:input_columns(andcolumn_names) from the unmodified header before applying--remove-columns, so conditions always index the input row layout and can filter on columns being removed from the output.--remove-columnsentries, computecolumn_schemeonce frominput_columns, and avoid splitting/rejoining dropped rows when--output-restis not set.pairtools/lib/select.py:TYPES(_types = TYPES.copy()) inevaluate_stream()instead of mutating the module-level default mapping._ColumnNameBinder(ast.NodeTransformer) +_compile_condition(), rewriting only unshadowedast.Namenodes inast.Loadcontext so string literals, attribute names, keyword argument names, f-string expressions (f"{mapq1=}"across Python 3.11/3.12+), lambda parameters, and comprehension targets are preserved.tests/test_select.py:--remove-columnswith downstream and removed-column filters (both selected and--output-reststreams),TYPESisolation across calls, and AST scoping / string-literal / f-string conditions.Verification
--remove-columns read_len1,read_len2and(mapq1>=30) and (mapq2>=30), baseline kept all 4 rows (0in--output-rest) by comparingread_len1/read_len2; patched matches the unprojected control (r1/r4selected,r2/r3in--output-rest, 12 output columns in both streams).(read_len1>=80) and (mapq1>=30)with--remove-columns read_len1): baseline raisesNameError; patched selects the matching rows and writes the 13-column projected output.pytest(46 passed) andflake8(0errors) on both Python 3.11 and Python 3.12, plus an independent CLI matrix across 21 filter/projection partitions.Found and written with AI agents; a separate AI referee reproduced the problem before this PR.
🤖 Generated with Claude Code
https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N