Skip to content

Cast line_idx to int64 in empty PDB record frames - #167

Merged
a-r-j merged 1 commit into
BioPandas:mainfrom
Mohit-Ak:fix/empty-frame-line-idx-dtype
Oct 17, 2026
Merged

a-r-j merged 1 commit into
BioPandas:mainfrom
Mohit-Ak:fix/empty-frame-line-idx-dtype

Conversation

@Mohit-Ak

Copy link
Copy Markdown
Contributor

Description

The line_idx column of an empty record DataFrame (e.g. ANISOU for a file without anisotropic records, or HETATM for a protein-only file) comes out as object, while non-empty frames get int64. _construct_df casts every column listed in pdb_records, but line_idx is appended separately and was never cast. This casts it to int64 after the existing dtype loop, as suggested in the issue.

Tested: the new test_line_idx_dtype_for_empty_records fails on main (dtype('O') for ANISOU in 3eiy.pdb) and passes with the change. Full pytest: 144 passed, 3 skipped, 14 xfailed. flake8 reports nothing new on the touched files.

Related issues or pull requests

Fixes #64

Pull Request Checklist

  • Added a note to docs/CHANGELOG.md
  • Added a unit test in tests/pdb/test_read_pdb.py
  • Ran pytest and all tests pass
  • Checked for style issues with flake8

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused implementation correctly resolves the dtype inconsistency and includes appropriate regression coverage.

0 open findings

What changed in this PR

Ensures line_idx consistently uses int64, including empty PDB record DataFrames.

Changes:

  • Casts line_idx to np.int64 during DataFrame construction.
  • Adds regression coverage for empty records.
  • Documents the fix for issue #64.
File Description
biopandas/​pdb/​pandas_pdb.py Applies the consistent line_idx dtype.
tests/​pdb/​test_read_pdb.py Verifies dtypes across record frames.
docs/​CHANGELOG.md Records the bug fix.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@a-r-j
a-r-j marked this pull request as ready for review October 17, 2026 16:47
@a-r-j
a-r-j merged commit ce1ba23 into BioPandas:main Oct 17, 2026
9 of 10 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.

column 'line_idx' gets 'object' d_type for empty frames.

3 participants