Repository navigation
Only cast mmCIF columns that are in the file - #169
Open
TheeCoderAhmed wants to merge 1 commit into
Open
TheeCoderAhmed wants to merge 1 commit into
TheeCoderAhmed wants to merge 1 commit into
Conversation
DataFrame.astype() raises a KeyError for dtype keys that are not columns, even with errors="ignore". mmCIF files whose atom_site loop lacks one of the columns in mmcif_col_types (for example auth_atom_id) could not be read. Fixes BioPandas#168
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.
Description
PandasMmcif._construct_df()casts the_atom_sitecolumns withfull_df.astype(mmcif_col_types, errors="ignore").errors="ignore"only covers values that fail to convert; pandas still raises aKeyErrorfor any key in the dtype dict that isn't a column. So any mmCIF file whose_atom_siteloop lacks one of the columns inmmcif_col_typescan't be read, which is what #168 hits withauth_atom_id:This builds the dtype dict from the columns that are actually present before calling
astype(). Files that have every column are cast exactly as before.Added
test_read_mmcif_without_auth_atom_idtotests/mmcif/test_read_mmcif.py, which reads a two-atom mmCIF withoutauth_atom_id(and a few other optional columns). It fails with theKeyErrorwithout the change and passes with it. The full test suite passes.Related issues or pull requests
Fixes #168
Pull Request Checklist
./docs/sources/CHANGELOG.mdfile (if applicable) (added todocs/CHANGELOG.md, where the current "Unreleased" section is)./biopandas/*/testsdirectories (if applicable)biopandas/docs/sources/(if applicable)PYTHONPATH='.' pytest ./biopandas -svand make sure that all unit tests passflake8 ./biopandas(no new warnings on the changed lines)