BUG: Fix AttributeError in from_adjlist when weight column is missing#859
Open
nimra06 wants to merge 2 commits into
Open
BUG: Fix AttributeError in from_adjlist when weight column is missing#859nimra06 wants to merge 2 commits into
nimra06 wants to merge 2 commits into
Conversation
Replace getattr() call with column existence check to properly handle DataFrames without the specified weight column. The previous code would raise AttributeError before checking if the column exists, making the fallback code unreachable. - Replace getattr(adjlist, weight_col) with weight_col in adjlist.columns check - Remove unreachable try_weightcol None check - Add tests for missing weight column scenarios Fixes pysal#669
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #859 +/- ##
=====================================
Coverage 85.5% 85.5%
=====================================
Files 151 151
Lines 16092 16105 +13
=====================================
+ Hits 13758 13773 +15
+ Misses 2334 2332 -2
🚀 New features to boost your workflow:
|
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.
pyteston your changes. Continuous integration will be run on all PRs with GitHub Actions, but it is good practice to test changes locally prior to a making a PR.pysal/masterbranch.docstrings and
unittests?
reviewer and added relevant labels
Found a bug in from_adjlist() where it crashes with AttributeError if the weight column doesn't exist in the DataFrame. The code was using getattr() to check for the column but that checks object attributes not DataFrame columns. So when the column is missing, it throws an error before it can create the default weight column.
I replaced the getattr() with weight_col in adjlist.columns which properly checks if the column exists. Now when the weight column is missing, it creates it with value 1 as the docstring says it should. Added a couple tests to make sure this works for both the default weight column and custom column names.
Fixes #669
AI assistance was used for code development. All explanations are written by me.