Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Different precision calling .astype(str) on float numbers #11302
Comments
|
what version of numpy? |
marcomayer
commented
Oct 12, 2015
|
numpy 1.10.0 |
|
in both cases? |
marcomayer
commented
Oct 12, 2015
|
in both cases yes. I updated with conda update pandas, which also updated numpy. Then I downgraded pandas with conda install pandas=0.16.2 and it worked again. |
|
this might be just a printing thing eg the display.precision changed in 0.17.0 |
marcomayer
commented
Oct 12, 2015
|
0.16.2:
0.17:
|
|
no see if the actual numbers are th same eg df.at[0,0] |
marcomayer
commented
Oct 12, 2015
|
0.16.2:
0.17:
|
|
0.16.2
0.17.0
This is python 2.7 on macosx. pls be more specific about python/os |
marcomayer
commented
Oct 12, 2015
|
do you get the same when using .to_dict()? Also I used the python console instead of ipython/notebook to make sure it's not a display issue cause by ipython. I'm running Python 3.4.3 :: Anaconda 2.3.0 (x86_64) on macosx. |
(numpy 1.10.1 just released, but doesn't have anything to do with this) |
|
so this is just on py3 looks like. |
|
so this goes thru a slightly different path that in 0.16.2 but not really sure why this would have changed. I'll mark it as a bug, though odd that you actually rely on this behavior? |
jreback
added Bug Numeric Output-Formatting
labels
Oct 12, 2015
jreback
added this to the
0.17.1
milestone
Oct 12, 2015
marcomayer
commented
Oct 13, 2015
|
thank you. I'm not sure about the "output-formatting" label though, isn't this more of a type-conversion/casting issue (float to str)? I rely on astype(str) for two things:
So I'll try now to find a way to make it through the unittests with 0.17 since I'd like to update due to the new features/optimizations. If you have an idea for a quick workaround let me know... |
marcomayer
commented
Oct 13, 2015
|
Regarding a workaround, this helps me for now to get through the unit-tests: df.applymap(lambda x: str(x)).to_dict() instead of df.astype(str).to_dict() Another difference I noticed is when np.NaN is converted to strings:
To be honest I wonder if it wouldn't be a good idea to get the same results with astype(str) as with the standard python str() function? For me there's a significant difference between an empty string and np.NaN. |
jreback
added a commit
to jreback/pandas
that referenced
this issue
Oct 13, 2015
|
|
jreback |
4f32b93
|
jreback
referenced
this issue
Oct 13, 2015
Merged
REGR: change in output formatting for long floats/nan, #11302 #11309
|
@marcomayer ok, should be fixed in #11309 a better way to compare things is just to use |
marcomayer
commented
Oct 13, 2015
|
that fixed it for me! thanks a lot! I'll also consider np.allclose() for the future. Marco |
marcomayer
closed this
Oct 13, 2015
jreback
added a commit
that referenced
this issue
Oct 13, 2015
|
|
jreback |
23b1c44
|
marcomayer commentedOct 12, 2015
With pandas 0.16.2:
With pandas 0.17:
I read the 0.17 release log but couldn't figure out why that is. Is it a bug or a new feature, and if it's a new feature how can I re-activate the old behavior?