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

NameError: argments is not defined #2190

Open
azzedineA opened this issue Aug 8, 2020 · 1 comment
Open

NameError: argments is not defined #2190

azzedineA opened this issue Aug 8, 2020 · 1 comment

Comments

@azzedineA
Copy link

I want to join between two files,but I get Error error : NameError: name 'names' is not defined

!python job.py data.txt --database item.txt

from mrjob.job import MRJob
from mrjob.step import MRStep
class MRPeopleScores(MRJob):
     def steps(self):
            return [
             MRStep(mapper=self.mapper_1,reducer_init=self.reducer_init, reducer=self.reducer_1)
         ]
   
    def configure_args(self):
        super(MRPeopleScores, self).configure_args()
        self.add_file_arg('--database')

    def mapper(self, _, line):
        (employee_id, age,var_,salary) = line.split("\t")
        yield int(employee_id), salary
        
    def reducer_init(self):
        
        with open("item.txt") as f:
            for line in f:
                fields = line.split('|')
                self.names[fields[0]] = fields[1] 

    def reducer(self,employee_id, salary):
        
        for salary_ in salary:
              yield employee_id,(salary_,names[employee_id])
   

if __name__ == '__main__':
    MRPeopleScores.run()
@manursanchez
Copy link

Hello:
I think that you should declare self.names=[] under reducer_init, and to add "self.names..." in the last yield.
Best.

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

2 participants