question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: Display Arithmetic Zero not Signed Zero aka 0 not -0

See original GitHub issue

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
>>> pd
<module 'pandas' from 'C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\pandas\\__init__.py'>
>>> pd.__version__
'1.4.3'
>>> pd.Series([1,None,0])*-1
0   -1.0
1    NaN
2   -0.0
dtype: float64
>>>

Issue Description

0 is being returned with a negative sign ie -0.0

Expected Behavior

There should be no negative on zero ie 0 * -1 = 0

Installed Versions

pd.version ‘1.4.3’

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mroeschkecommented, Aug 24, 2022

This behavior mimics numpy

In [4]: np.array([1.0, np.nan, 0.0]) * -1
Out[4]: array([-1., nan, -0.])

Generally, -0 is defined by IEEE and essentially acts like 0/+0. https://stackoverflow.com/a/4083431

Nonetheless, if this behavior was undesirable, it would need to be fixed in numpy/CPython so closing as a potential upstream issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why computers have two floating point zeros: +0 and -0
Here's a strange detail of IEEE floating point arithmetic: computers have two versions of 0: positive zero and negative zero.
Read more >
Signed zero
Signed zero is zero with an associated sign. In ordinary arithmetic, the number 0 does not have a sign, so that −0, +0...
Read more >
When is a zero not a zero? - Revolution Analytics
The short answer is that R, like pretty much every other numerical software in existence, uses floating point arithmetic to do its calculations....
Read more >
Handling the ArithmeticException Runtime Exception in Java
The ArithmeticException in Java is thrown by the JVM when an arithmetic operation creates an exceptional condition.
Read more >
algebra precalculus - Zero to the zero power – is $0^0=1
In Calculus and algebra, there is no reasonable definition (the closest you can come up with is trying to justify it via the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found