Skip to content

Data corruption in DataFrame when creating new columns while iterating over the index #2453

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
rafaljozefowicz opened this issue Dec 7, 2012 · 2 comments
Labels
Milestone

Comments

@rafaljozefowicz
Copy link

That's the shortest example I could find. Data gets somehow corrupted when creating new columns while iterating over the index. Pre-generating initial values for columns solved my problem (commented out part)
I am using pandas 0.9.0

df = pd.DataFrame(index=[0,1])
df[0] = nan
wasCol = {}
# uncommenting these makes the results match
#for col in xrange(100, 200):
#    wasCol[col] = 1
#    df[col] = nan

for i, dt in enumerate(df.index):
    for col in xrange(100, 200):
        if not col in wasCol:
            wasCol[col] = 1
            df[col] = nan
        df[col][dt] = i

myid = 100
print(len(df.ix[isnan(df[myid]), [myid]]))
print(len(df.ix[isnan(df[myid]), [myid]]))

Outputs:

0
1
@wesm
Copy link
Member

wesm commented Dec 7, 2012

Looks fine on the development version. I'll see if I can figure out what was going wrong so I can add a unit test

@wesm
Copy link
Member

wesm commented Dec 8, 2012

Well, I can verify this was fixed in 5d6e7c8-- the bug is still present in v0.9.1. I would suggest upgrading to 0.10.0 or the development version as soon as practical. I'll add a unit test for your example

@wesm wesm closed this as completed in 7e53266 Dec 8, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants