From a66340c057165f5465cb03f05c1b3f7a3b96c79b Mon Sep 17 00:00:00 2001 From: Mohit Ak Date: Sun, 11 Oct 2026 02:13:12 -0400 Subject: [PATCH] Cast line_idx to int64 in empty PDB record frames Fixes #64 --- biopandas/pdb/pandas_pdb.py | 1 + docs/CHANGELOG.md | 2 ++ tests/pdb/test_read_pdb.py | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/biopandas/pdb/pandas_pdb.py b/biopandas/pdb/pandas_pdb.py index c4d2a00..688f76a 100644 --- a/biopandas/pdb/pandas_pdb.py +++ b/biopandas/pdb/pandas_pdb.py @@ -564,6 +564,7 @@ def _construct_df(pdb_lines): except ValueError: # expect ValueError if float/int columns are empty strings df[c["id"]] = pd.Series(np.nan, index=df.index) + df["line_idx"] = df["line_idx"].astype(np.int64) dfs[r[0]] = df diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 0e47d91..6b65ad6 100755 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -13,6 +13,8 @@ The CHANGELOG for the current development version is available at - Fix: `PandasPdb.to_pdb()` no longer fails with a `TypeError` on structures with `ANISOU` records after `label_models()`. The `model_id` column is now skipped silently, like in `to_pdb_stream()`, and other unexpected `ANISOU` columns are skipped with a warning, as for `ATOM` and `HETATM`. Addresses issue [#124](https://github.com/BioPandas/biopandas/issues/124). +- Fix: `line_idx` is now `int64` in empty record DataFrames (e.g. `ANISOU` for a file without anisotropic records) instead of `object`, matching non-empty frames. Addresses issue [#64](https://github.com/BioPandas/biopandas/issues/64). + ### 0.5.2 (24/08/2026) - Fix: improves robustness of `amino3to1` residue identification by handling `NaN` insertion codes (NumPy 2.4+ compatibility) and including chain IDs and separators to avoid collisions. PR [#157](https://github.com/BioPandas/biopandas/pull/157) diff --git a/tests/pdb/test_read_pdb.py b/tests/pdb/test_read_pdb.py index e83c061..51e51da 100644 --- a/tests/pdb/test_read_pdb.py +++ b/tests/pdb/test_read_pdb.py @@ -271,6 +271,14 @@ def test_read_pdb_from_list(): assert ppdb.pdb_path == "" +def test_line_idx_dtype_for_empty_records(): + ppdb = PandasPdb() + ppdb.read_pdb(TESTDATA_FILENAME) + assert ppdb.df["ANISOU"].empty + for record in ("ATOM", "HETATM", "ANISOU", "OTHERS"): + assert ppdb.df[record]["line_idx"].dtype == np.int64 + + def test_anisou_input_handling(): """Test public read_pdb""" ppdb = PandasPdb()