Skip to content

Reindex MultiIndex of type float #10169

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
leroygr opened this issue May 19, 2015 · 3 comments
Closed

Reindex MultiIndex of type float #10169

leroygr opened this issue May 19, 2015 · 3 comments
Labels
Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@leroygr
Copy link

leroygr commented May 19, 2015

Hi,

There is a strange behavior when I want to reindex a Multi-Index (float64) of a Series: some of the original values are dropped from the reindexed object.

Here is the test case:

>>> import pandas as pd
>>> import numpy as np

>>> df_g=pd.Series(index=pd.MultiIndex.from_tuples([(10.,4.2),(11.,5.2),(14,7.8)]),data=[0.01,0.2,0.684])
10  4.2    0.010
11  5.2    0.200
14  7.8    0.684
dtype: float64

>>> df_g_r=pd.Series(index=pd.MultiIndex.from_product([np.arange(0,360,1.),np.arange(0,25,0.1)])).fillna(0)

>>> df_g.reindex(df_g_r.index).dropna()
10  4.2    0.01
11  5.2    0.20
dtype: float64

Anyone has an idea of what is going on? Is there any workaround for this?

Many thanks,
Greg

INSTALLED VERSIONS

commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Linux
OS-release: 3.13.0-51-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.15.2
nose: 1.3.4
Cython: 0.21.2
numpy: 1.8.2
scipy: 0.15.1
statsmodels: None
IPython: 2.3.1
sphinx: 1.2.2
patsy: 0.3.0
dateutil: 2.4.2
pytz: 2015.4
bottleneck: 0.8.0
tables: 3.1.1
numexpr: 2.4
matplotlib: 1.4.2
openpyxl: 1.8.6
xlrd: 0.9.3
xlwt: 0.7.5
xlsxwriter: None
lxml: 3.3.3
bs4: None
html5lib: None
httplib2: 0.8
apiclient: None
rpy2: None
sqlalchemy: 0.9.8
pymysql: 0.6.6.None
psycopg2: None

@leroygr
Copy link
Author

leroygr commented May 19, 2015

FYI, I managed to solve the issue by using np.around when building the multi-index of df_g_r object:

>>> df_g_r=pd.Series(index=pd.MultiIndex.from_product([np.around(np.arange(0,360,1.),decimals=5),np.around(np.arange(0,25,0.1),decimals=5)])).fillna(0)
>>> df_g.reindex(df_g_r.index).dropna()
10  4.2    0.010
11  5.2    0.200
14  7.8    0.684
dtype: float64

@shoyer
Copy link
Member

shoyer commented May 19, 2015

This is a floating point precision issue. See #9817

@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Reshaping Concat, Merge/Join, Stack/Unstack, Explode Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request labels May 20, 2015
@jreback
Copy link
Contributor

jreback commented May 20, 2015

closing as a dupe of #9817

@jreback jreback closed this as completed May 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

3 participants