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

Problem with Dataframe apply function #592

Open
imachraoui opened this issue Apr 8, 2024 · 1 comment
Open

Problem with Dataframe apply function #592

imachraoui opened this issue Apr 8, 2024 · 1 comment
Assignees
Labels
api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@imachraoui
Copy link

Hello,

I am a new user of bigframes package.

I was trying to execute some code but I am facing a problem that i am not able to solve.

I am trying to use the apply function on a Dataframe with the parameter axis=1 , but it doesn't seem to work. I always have an error message.

Can you please help me with this?

Thanks.

Regards,

Code example

# example
def condition(row):
    print(row )
    if 1 <= row["debres_month"] <= 6:
        return f"{row['debres_year']:02}S1{row['CODPYC']}{row['CODDEV']}"
    else:
        return f"{row['debres_year']:02}S2{row['CODPYC']}{row['CODDEV']}"

valodetail_df['IDTDCI'] = valodetail_df.apply(condition,axis=1)

Stack trace

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/miniconda3/envs/qback/lib/python3.11/site-packages/bigframes/core/log_adapter.py", line 44, in wrapper
    return method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/qback/lib/python3.11/site-packages/bigframes/dataframe.py", line 3118, in apply
    results = {name: func(col, *args, **kwargs) for name, col in self.items()}
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/qback/lib/python3.11/site-packages/bigframes/dataframe.py", line 3118, in <dictcomp>
    results = {name: func(col, *args, **kwargs) for name, col in self.items()}
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<stdin>", line 3, in condition
  File "missing.pyx", line 419, in pandas._libs.missing.NAType.__bool__
TypeError: boolean value of NA is ambiguous
>>> valodetail_df['IDTDCI'] = valodetail_df.apply(condition,axis=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/miniconda3/envs/qback/lib/python3.11/site-packages/bigframes/core/log_adapter.py", line 44, in wrapper
    return method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/qback/lib/python3.11/site-packages/bigframes/dataframe.py", line 3118, in apply
    results = {name: func(col, *args, **kwargs) for name, col in self.items()}
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/miniconda3/envs/qback/lib/python3.11/site-packages/bigframes/dataframe.py", line 3118, in <dictcomp>
    results = {name: func(col, *args, **kwargs) for name, col in self.items()}
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: condition() got an unexpected keyword argument 'axis'

@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. label Apr 8, 2024
@chelsea-lin chelsea-lin added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Apr 9, 2024
@shobsi
Copy link
Contributor

shobsi commented Apr 16, 2024

This is a current work in progress, however I replied on this related stackoverflow post which may be used to unblock for the time being
https://stackoverflow.com/questions/78297873/bigframes-package-problem-with-dataframe-apply-function/78331896#78331896

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

3 participants