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

ENH: Shall we let pd.NA * 0 equals to zero? #47117

Open
tushushu opened this issue May 25, 2022 · 4 comments
Open

ENH: Shall we let pd.NA * 0 equals to zero? #47117

tushushu opened this issue May 25, 2022 · 4 comments
Labels
API Design Enhancement NA - MaskedArrays Related to pd.NA and nullable extension arrays Needs Discussion Requires discussion from core team before further action

Comments

@tushushu
Copy link
Contributor

tushushu commented May 25, 2022

Is your feature request related to a problem?

I found that:

pd.NA ** 0 # The result is 1
pd.NA * 0 # The result is pd.NA

Describe the solution you'd like

Personally, I think the pow and mul method shoulds be consistent. The results should be both NA or both numbers.
Solution 1:

pd.NA ** 0 # The result is pd.NA
pd.NA * 0 # The result is pd.NA

Solution 2:

pd.NA ** 0 # The result is 1
pd.NA * 0 # The result is 0

PS: I assume the pd.NA is not infinite.

@tushushu tushushu added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels May 25, 2022
@TomAugspurger
Copy link
Contributor

xref #29997.

PS: I assume the pd.NA is not infinite.

I think that's the issue. Similar to how np.inf * 0 isn't defined (returns np.nan) we don't know what the output of pd.NA * 0 should be. That differs from pd.NA ** 0 which is 1 by definition.

@tushushu
Copy link
Contributor Author

That makes sense. But NA**0 == 1 is also confusing, shouldn't it be 1 or 1.0? How do we know the NA is representing a integer?

@TomAugspurger
Copy link
Contributor

I think that gets into a larger discussion around "typed NA" (or NA[T]). #28095

@tushushu
Copy link
Contributor Author

tushushu commented May 26, 2022

Thanks @TomAugspurger for sharing these discussions, it's really insightful.

@lithomas1 lithomas1 added API Design Needs Discussion Requires discussion from core team before further action NA - MaskedArrays Related to pd.NA and nullable extension arrays and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Enhancement NA - MaskedArrays Related to pd.NA and nullable extension arrays Needs Discussion Requires discussion from core team before further action
Projects
None yet
Development

No branches or pull requests

3 participants