Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

yaduart
Copy link
Contributor

@yaduart yaduart commented May 10, 2016

Closes #11981

Updated the v0.18.2 document

In the function __call__ of EngFormatter check if decimal input is NaN.

@yaduart yaduart changed the title BUG: Added checks for Nan in __call__ of EngFormatter BUG: Added checks for NaN in __call__ of EngFormatter May 10, 2016
@@ -3925,6 +3925,10 @@ def test_rounding(self):
result = formatter(0)
self.assertEqual(result, u(' 0.000'))

def test_nan(self):
Copy link
Contributor

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

@jreback jreback added Bug Output-Formatting __repr__ of pandas objects, to_string labels May 10, 2016
@jreback jreback added this to the 0.18.2 milestone May 10, 2016
def test_nan(self):
formatter = fmt.EngFormatter(accuracy=1, use_eng_prefix=True)
result = formatter(np.nan)
self.assertEqual(result, u('NaN'))

Copy link
Contributor

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)

Copy link
Contributor Author

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"

Copy link
Contributor

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

Copy link
Contributor Author

@yaduart yaduart May 10, 2016

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)

Copy link
Contributor Author

@yaduart yaduart May 10, 2016

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]})

Copy link
Contributor

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.

Copy link
Contributor Author

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

@jreback
Copy link
Contributor

jreback commented May 10, 2016

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
@codecov-io
Copy link

Current coverage is 84.14%

Merging #13124 into master will decrease coverage by -<.01%

@@             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          
  1. File ...das/tseries/index.py (not in diff) was modified. more
    • Misses +1
    • Partials 0
    • Hits -1

Powered by Codecov. Last updated by 43989fd...d7315dd

@yaduart
Copy link
Contributor Author

yaduart commented May 11, 2016

@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.

File "/usr/share/google/boto/boto_plugins/compute_auth.py", line 64

    except (urllib2.URLError, urllib2.HTTPError, IOError), e:

                                                         ^
SyntaxError: invalid syntax

Is this Pandas error or testing framework error. Should I run the Travis again.

@jreback jreback closed this in d0734ba May 11, 2016
@jreback
Copy link
Contributor

jreback commented May 11, 2016

thanks @yaduart

@yaduart
Copy link
Contributor Author

yaduart commented May 11, 2016

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.

@jreback
Copy link
Contributor

jreback commented May 11, 2016

@yaduart no, I merged it via d0734ba

it is a slightly edited commit. When I merged it closed the PR and the issue.

thanks for the contribution.

@jreback
Copy link
Contributor

jreback commented May 11, 2016

If I had closed it for another reason (e.g. not accepting) or something would always write something.

@yaduart
Copy link
Contributor Author

yaduart commented May 11, 2016

Why was the travis-ci check failing earlier?

@jreback
Copy link
Contributor

jreback commented May 11, 2016

unrelated, we picked up a broken boto version (not sure why it was released), and were importing it on main pandas import (which is wrong, but that's how it was).

@yaduart
Copy link
Contributor Author

yaduart commented May 11, 2016

Thanks for clarifying. Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

interation of set_eng_float_format and pivot_tables
3 participants