i thought i understood the global vs local scope for variable but i am struggling on a case.
Here the function i want to implement:
def login_table(id_name_verified, id_password):
"""
:param id_name_verified: (DataFrame) DataFrame with columns: Id, Login, Verified.
:param id_password: (numpy.array) Two-dimensional NumPy array where each element
is an array that contains: Id and Password
:returns: (None) The function should modify id_name_verified DataFrame in-place.
It should not return anything.
Goal : in id_name_verified, 'Verified' column should be removed and password should be added from id_password with corresponding id and the column be named password
"""
Test:
import pandas as pd
import numpy as np
def login_table(id_name_verified, id_password):
id_name_verified.drop(columns="Verified",inplace=True)
password = pd.DataFrame(id_password)
password.columns = ["Id", "Password"]
id_name_verified =id_name_verified.merge(password, on=['Id'])
id_name_verified = pd.DataFrame([[1, "JohnDoe", True], [2, "AnnFranklin", False]], columns=["Id", "Login", "Verified"])
id_password = np.array([[1, 987340123], [2, 187031122]], np.int32)
login_table(id_name_verified, id_password)
print(id_name_verified)
Expected Output:
Id Login Password
0 1 JohnDoe 987340123
1 2 AnnFranklin 187031122
Output i got:
Id Login
0 1 JohnDoe
1 2 AnnFranklin
When I run this on pycharm, i see the problem is in the last line of my function where id_name_verified is identified as being from outer scope.
This inspection detects shadowing names defined in outer scopes.
If i don't define a function it will work so I guess there is something I miss in the understanding of parameters pass to a function; any suggestions ?
login_table()shouldreturn id_name_verifiedand the call site should be:id_name_verified = login_table(id_name_verified, id_password)