-
Notifications
You must be signed in to change notification settings - Fork 58
Add input validation for out-of-bounds column numbers in cload.py. #461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ShigrafS
wants to merge
16
commits into
open2c:master
Choose a base branch
from
ShigrafS:add-validation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
…o rea-chromsize in util.py
for more information, see https://pre-commit.ci
Co-authored-by: Nezar Abdennur <[email protected]>
for more information, see https://pre-commit.ci
- Added validate_pairs_columns to check column indices against file content.
- Updated get_header to use readline() instead of peek() for test compatibility.
- Modified pairs to use validate_pairs_columns stream, added kwargs = {}, removed duplicate call.
- Created 7 pytest cases in test_cload.py to test valid/invalid indices, stdin, headers, empty files, and extra fields. - Ensures validate_pairs_columns and pairs handle file and stdin inputs correctly.
…ty with Python 3.9 in cload.py.
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: #209
Original Issues: #135
Related Issues:
cooler cloadOverview
This pull request adds input validation for column indices in the
cooler cloadcommand to catch out-of-bounds values early and provide clear error messages. Previously, if a user specified a column index larger than the number of columns in the file, the program failed with an unhelpfulValueError: No objects to concatenatetraceback. This update prevents that by checking the indices against the file’s actual column count, raising a detailed error if invalid indices are detected.What Was Happening Before?
The Problem:
When users passed column indices beyond the number of available columns (e.g.,
-c2 4 -p2 5for a file with only 4 columns),pandasfailed silently during concatenation, leading to a vague traceback.Example Error:
This error offered no guidance on the actual issue, making debugging frustrating.
What’s Changed?
This update introduces proactive validation of column indices and streamlines file handling for better error reporting and compatibility with standard input.
Input Validation (
validate_pairs_columns)cload.pyto validate column indices against the actual number of columns in the input file.ValueErrorwith a clear message if any index is out of bounds.Header Handling (
get_header)peek()dependency (which broke withStringIOduring tests).readline()to handle headers, buffers remaining content, and returns a new stream if needed.Updated
pairsCommandvalidate_pairs_columns, centralizing validation logic.get_headercalls and fixed potential double-read issues with stdin.kwargs = {}beforepd.read_csvto preventClickoption leakage causingTypeError.How It Works Now
Valid Case:
✅ Passes and proceeds with loading.
Invalid Column Index:
❌ Fails early with:
Empty or Header-Only File:
❌ Fails with:
Benefits
StringIOimprove compatibility for piped input and testing.Testing
New Tests (7 cases in
tests/test_cload.py)Coverage:
cload.py, with untested lines only in unrelated subcommands.pytestand passed all tests:Notes
htmlcov/andcoverage.xml.