3

Is there any way to prevent pandas from changing the default print format for numpy arrays?

With plain numpy, I get:

>>> numpy.array([123.45, 0.06])
array([  1.23450000e+02,   6.00000000e-02])

After I import pandas, I get:

>>> numpy.array([123.45, 0.06])
array([ 123.45,    0.06])

Can I stop it from doing this as a configuration setting? I don't want to have to wrap every "import pandas" with a "foo=np.get_printoptions(); import pandas; np.set_printoptions(**foo)", but that's the best I can come up with.

As it is, if I import pandas in one place, I get doctest errors from another.

2 Answers 2

2

You should only have to wrap the first import pandas with np.set_printoptions(foo) since python will cache it. See below:

import numpy
>>> numpy.array([123.45, 0.06])
array([  1.23450000e+02,   6.00000000e-02])
>>> import pandas
>>> numpy.array([123.45, 0.06])
array([ 123.45,    0.06])
>>> numpy.set_printoptions(edgeitems=3,infstr='inf', linewidth=75, nanstr='nan', precision=8, suppress=False, threshold=1000)
>>> numpy.array([123.45, 0.06])
array([  1.23450000e+02,   6.00000000e-02])
>>> import pandas
>>> numpy.array([123.45, 0.06])
array([  1.23450000e+02,   6.00000000e-02])
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but we're using nose to load in the tests, which means I don't know in what order the modules will be loaded. I could always put it in the top package-level init, but that feels invasive. Plus, I'd have to change everyone else's doctests. I can't help but think that pandas shouldn't be changing numpy package-level globals.
1

This is a bit irritating as I think that NumPy should have suppress=True as its default. I'm changing pandas to not change it.

1 Comment

Thanks, Wes! That would be great. If I run into you at DataGotham, I'll say thanks in person.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.