Home > Enterprise >  TypeError: zip argument #1 must support iteration when using lambda function with zip
TypeError: zip argument #1 must support iteration when using lambda function with zip

Time:10-28

I have some code below that gives me an error message of

TypeError: zip argument #1 must support iteration.

I believe the error is due to the function:

get_account_jira_account_name(year_month, outage['tenant'])

returning Empty.

I am wondering how can I return an Empty value that can support iteration?


def get_account_jira_account_name(year_month, tenant):
    sql_tenant_account = f'''
    Some query";'''
    df=get_dataframe(sql_tenant_account)

    if not df.empty:
        account_name = df['account_name'].values[0]
        jira_account_name = df['jira_account_name'].values[0]
    else:
        sql_tenant_account = f'''Some Query";
        ;'''
        df=get_dataframe(sql_tenant_account,'sla','COMMONDB')
        if len(df) !=0:
            account_name = df['account_name'].values[0]
            jira_account_name = ''
            return account_name, jira_account_name
        else:
            print('When I get the error it happens here')
            account_name = 'not found'
            jira_account_name = 'not found'
            return account_name, jira_account_name
outage_df['account_name'], outage_df['jira_account_name'] = zip(*outage_df.apply(lambda outage: get_account_jira_account_name(year_month, outage['tenant']), axis=1))

CodePudding user response:

Technically speaking, an empty sequence (empty list, empty string, etc.) is "an empty value that supports iteration."

However, you haven't shown enough of your code for us to know if that solution would actually work in your specific situation.

In your function, when the first if statement is true, no return statement is executed at all*, therefore the function returns a single None value by default, which is not iterable.

* And this seems strange, because in the first if block, the function goes to the effort of assigning values for account_name and jira_account_name, but then doesn't actually do anything with them. Perhaps you meant to have return account_name, jira_account_name in that block also?)

  • Related