Skip to content

Cannot use np.round or np.around on Float64Index #7446

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
hughesadam87 opened this issue Jun 12, 2014 · 5 comments
Closed

Cannot use np.round or np.around on Float64Index #7446

hughesadam87 opened this issue Jun 12, 2014 · 5 comments

Comments

@hughesadam87
Copy link

np.round()/np.around() currently don't work on Flaot64Index, because the Float64Index is throwing an error when Float64Index.round() is called.

In our application, we are getting floating point digit discrepancies when doing subtraction and other floating point operations on these indicies, and I believe rounding would solve the problem.

Original mailing list thread:

https://groups.google.com/forum/#!topic/pydata/8aTLVKrPJfs

I'm using pandas.read_csv(), so I can't access the data apriori to it being written into a dataframe to round it before instantiation.

@jreback
Copy link
Contributor

jreback commented Jun 12, 2014

pls show exact code which is not working as well as pd.show_versions()

@shoyer
Copy link
Member

shoyer commented Jun 19, 2014

np.around works for me using pandas 0.14.0 and numpy 1.8.1 on Python 2.7:

import numpy as np
import pandas as pd
idx = pd.Index(0.5 * np.arange(5))
print idx
print np.around(idx)
Float64Index([0.0, 0.5, 1.0, 1.5, 2.0], dtype='float64')
Float64Index([0.0, 0.0, 1.0, 2.0, 2.0], dtype='float64')

@hughesadam87
Copy link
Author

Sorry if this issue appeared twice; doesn't seem to be showing up in my "created by you" list.

I was accidentally using a VE with pandas 0.13.1. It seems to have been corrected since. Here is the full error.

  In [1]: import numpy as np

  In [2]: import pandas as pd

  In [3]: idx = pd.Index(0.5 * np.arange(5))

  In [4]: print idx
  Float64Index([0.0, 0.5, 1.0, 1.5, 2.0], dtype='object')

  In [5]: print np.around(idx)
  ---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  <ipython-input-5-cd6106b80ffb> in <module>()
  ----> 1 print np.around(idx)

  /home/glue/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/core/fromnumeric.pyc in around(a, decimals, out)
     2609     except AttributeError:
     2610         return _wrapit(a, 'round', decimals, out)
  -> 2611     return round(decimals, out)
     2612 
     2613 

  AttributeError: rint

  In [6]: print np.round(idx)
  ---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  <ipython-input-6-69683a0affaf> in <module>()
  ----> 1 print np.round(idx)

  /home/glue/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/core/fromnumeric.pyc in round_(a, decimals, out)
     2627     except AttributeError:
     2628         return _wrapit(a, 'round', decimals, out)
  -> 2629     return round(decimals, out)
     2630 
     2631 

  AttributeError: rint

@shoyer
Copy link
Member

shoyer commented Jun 19, 2014

This is likely thanks to a change in how Float64Index is stored internally in 0.14: #6471

@hughesadam87
Copy link
Author

Tight, thanks for the help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants