Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try_weightcol is incorrectly defined using getattr() #669

Open
Ryclock opened this issue Dec 20, 2023 · 2 comments
Open

try_weightcol is incorrectly defined using getattr() #669

Ryclock opened this issue Dec 20, 2023 · 2 comments

Comments

@Ryclock
Copy link

Ryclock commented Dec 20, 2023

Question Description

In line 372 of the libpysal/weights/weights.py file, the getattr function is called to assign a value to try_weightcol. However, since the third parameter of getattr (the default value to be returned when the attribute is not found) is not passed, it will result in an AttributeError: 'DataFrame' object has no attribute 'weight' if the 'weight_col' column is not present in the 'adjlist', and this will terminate the program.

So, when will the code at lines 373-375 be executed?

if try_weightcol is None:
    adjlist = adjlist.copy(deep=True)
    adjlist["weight"] = 1

Essential Information

  • Platform information: nt win32
  • Python version: 3.10.11[MSC v.1934 64 bit (AMD64)]
  • SciPy version:1.10.1
  • NumPy version:1.24.3
@ljwolf
Copy link
Member

ljwolf commented Dec 20, 2023

Thank you for the report!

Yes, I think this should instead use the data frame's .get() method rather than getattr()

try_weightcol = adjlist.get(weight_col)

This should be a fairly straightforward fix.

@ljwolf ljwolf changed the title useless code of try_weightcol try_weightcol is incorrectly defined using getattr() Dec 20, 2023
@Ryclock Ryclock closed this as completed Mar 10, 2024
@martinfleis martinfleis reopened this Mar 10, 2024
@martinfleis
Copy link
Member

I don't think it has been fixed yet.

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

No branches or pull requests

3 participants