Skip to content

BUG: pd.DataFrame.mul has not support fill_value? #61581

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

Open
3 tasks done
TungPhaSanh opened this issue Jun 6, 2025 · 3 comments
Open
3 tasks done

BUG: pd.DataFrame.mul has not support fill_value? #61581

TungPhaSanh opened this issue Jun 6, 2025 · 3 comments
Labels
Bug Needs Info Clarification about behavior needed to assess issue Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@TungPhaSanh
Copy link

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
df = pd.DataFrame(np.arange(12).reshape(3,4))
s = [1,pd.NA,3]
df.mul(s, axis="columns", fill_value=0)

Issue Description

It raise error: fill_value=0 is not supported

Expected Behavior

It should return the result with filled NA value of 0

Installed Versions

2.3.0

@TungPhaSanh TungPhaSanh added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 6, 2025
@sanggon6107
Copy link

Hi @TungPhaSanh ,

It seems the example code doesn't work because s only has 3 elements - I think it needs 4.

I have tried this on the main branch, but mul seems to work fine when fill_value=0.

>>> import pandas as pd
>>> import numpy as np

>>> df = pd.DataFrame(np.arange(12).reshape(3,4))
>>> df
   0  1   2   3
0  0  1   2   3
1  4  5   6   7
2  8  9  10  11
>>> s = [1,pd.NA,3, 4]
>>> s
[1, <NA>, 3, 4]
>>> df.mul(s, axis="columns", fill_value=0)
   0  1   2   3
0  0  0   6  12
1  4  0  18  28
2  8  0  30  44

@TungPhaSanh
Copy link
Author

TungPhaSanh commented Jun 6, 2025

Thanks @sanggon6107

My bad. Sorry with my example, the true one is:

import pandas as pd
df = pd.DataFrame(np.arange(12).reshape(3,4))
s = [1,pd.NA,3]
df.mul(s, axis="index", fill_value=0) # index instead of columns

I have try it, it is okay, but sometimes in my project it raise error fill_value=0 is not supported. I have to fillna first before doing multiplication.

@asishm asishm added the Needs Info Clarification about behavior needed to assess issue label Jun 6, 2025
@asishm
Copy link
Contributor

asishm commented Jun 6, 2025

Thanks for the report. Your example doesn't reproduce for me on latest release (2.3.0) with axis='index'.

Can you confirm your example provided currently fails for you and if so, please provide the full traceback. If not, please update your post with a reproducible example. Thanks!

>>> df
   0  1   2   3
0  0  1   2   3
1  4  5   6   7
2  8  9  10  11
>>> s = [1,pd.NA,3]
>>> df.mul(s, axis="index", fill_value=0)
    0   1   2   3
0   0   1   2   3
1   0   0   0   0
2  24  27  30  33
>>> pd.__version__
'2.3.0'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Info Clarification about behavior needed to assess issue Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

3 participants