-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Added checks for NaN in __call__ of EngFormatter #13124
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
Conversation
@@ -3925,6 +3925,10 @@ def test_rounding(self): | |||
result = formatter(0) | |||
self.assertEqual(result, u(' 0.000')) | |||
|
|||
def test_nan(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the issue number here as a comment
def test_nan(self): | ||
formatter = fmt.EngFormatter(accuracy=1, use_eng_prefix=True) | ||
result = formatter(np.nan) | ||
self.assertEqual(result, u('NaN')) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also add the example from the issue as well (its just a smoke test, you don't need to compare it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please tell me what you meant by "its just a smoke test, you don't need to compare it"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just add what the issue does in the test
it raises now so your fix your make it pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct?
def test_nan(self):
formatter = fmt.EngFormatter(accuracy=1, use_eng_prefix=True)
result = formatter(np.nan)
self.assertEqual(result, u('NaN'))
df = pd.DataFrame({'a':[1.5, 10.3, 20.5], 'b':[50.3, 60.67, 70.12], 'c':[100.2, 101.33, 120.33]})
pt = df.pivot_table(values='a', index='b', columns='c')
fmt.set_eng_float_format(accuracy=1)
result = pt.to_string()
expected = ('c 100.2E+00 101.3E+00 120.3E+00\n'
'b \n'
'50.3E+00 1.5E+00 NaN NaN\n'
'60.7E+00 NaN 10.3E+00 NaN\n'
'70.1E+00 NaN NaN 20.5E+00')
self.assertEqual(result, expected)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example in the issue had random initialization, I have changed it so that I can expect the results.
example in the issue:
df = pd.DataFrame(data = np.random.randint(25, size=(10, 3)), columns = list('abc'))
testcase:
df = pd.DataFrame({'a':[1.5, 10.3, 20.5], 'b':[50.3, 60.67, 70.12], 'c':[100.2, 101.33, 120.33]})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you didn't really need to actually compare the pt.to_string()
(just run it; if it doesn't raise then you are good). that's what I mean by smoke test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay...I got it now. Thanks
once you have made the changes and pushed, ping on green. |
Closes pandas-dev#11981 Updated the v0.18.2 document Updated the document v0.18.2.txt and the test test_nan Updated test_nan for smoke test
Current coverage is 84.14%@@ master #13124 diff @@
==========================================
Files 137 137
Lines 50287 50289 +2
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 42312 42313 +1
- Misses 7975 7976 +1
Partials 0 0
|
@jreback the Travis-ci build job 19538.5 has failed for Python 3.5, as except with comma is not valid in Python 3. But, surprisingly the tests have passed for Python 3.4.
Is this Pandas error or testing framework error. Should I run the Travis again. |
thanks @yaduart |
As I am a newbie here, I am not sure of the processes. It would help me understand how to close the pull request, if you could tell how you decided to close the pull request as the Travis-ci checks were failing, or did you run them again, or was the Travis-ci bypassed. |
If I had closed it for another reason (e.g. not accepting) or something would always write something. |
Why was the travis-ci check failing earlier? |
unrelated, we picked up a broken |
Thanks for clarifying. Cheers |
git diff upstream/master | flake8 --diff
Closes #11981
Updated the v0.18.2 document
In the function
__call__
of EngFormatter check if decimal input is NaN.