Skip to content

Use positional access for the reference row in build_tables#24

Open
arpitjain099 wants to merge 1 commit into
USDA-VS:mainfrom
arpitjain099:chore/series-positional-access
Open

Use positional access for the reference row in build_tables#24
arpitjain099 wants to merge 1 commit into
USDA-VS:mainfrom
arpitjain099:chore/series-positional-access

Conversation

@arpitjain099

Copy link
Copy Markdown

Fixes #22.

build_tables in bin/vsnp3_fasta_to_snps_table.py reads the first (root/reference) row of each column with column[0] at three sites (lines 290, 304, 335). The column is a pandas.Series indexed by sample-name strings, so column[0] is a label lookup for the label 0, not positional access. On pandas 2.x that still worked but emitted a deprecation warning; on pandas 3.x it fails hard with KeyError: 0, which crashes cascade-table construction during Step 2 (traceback in the issue).

The fix is column.iloc[0], which is the positional access the code intends - the comment on line 290 even notes that column[0] is the top row / root / reference. The value returned is unchanged (the first/top row), so behavior is the same on older pandas and no longer crashes on newer pandas.

The repo has no test harness for this module, so I verified the semantics directly: for a string-indexed Series, s.iloc[0] returns the first element while s[0] raises KeyError on pandas 3.x (and warns on 2.x). python -m py_compile on the changed file passes.

build_tables read the first (root/reference) row of each column with
column[0]. Because the Series is indexed by sample-name strings, [0] is a
label lookup, not a positional one. On pandas 2.x that raised a
deprecation warning and on pandas 3.x it fails hard with KeyError: 0,
crashing cascade-table construction during Step 2.

Switch the three sites to column.iloc[0], which is the positional access
the code intends (the comment notes column[0] is the top row / root /
reference).

Fixes USDA-VS#22

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
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.

Step 2 KeyError: 0 — column[0] on Series with non-integer index (pandas 2.x/3.x)

1 participant