Skip to content
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

Cannot fill inserted column of NaNs #304

Closed
Komnomnomnom opened this issue Oct 27, 2011 · 2 comments

Comments

@Komnomnomnom
Copy link
Contributor

commented Oct 27, 2011

After inserting a column of NaNs into a preexisting DataFrame its contents cannot be filled using advanced indexing. See test case below.

This only appears to happen if the existing DataFrame is filled with floats, i.e. it works fine for ints.

Tested with pandas 0.5 and latest github snapshot.

from pandas import DataFrame
import numpy as np

print '\n***RESULT\n'

df = DataFrame({'x': [1.1, 2.1, 3.1, 4.1], 'y': [5.1, 6.1, 7.1, 8.1]}, index=[0,1,2,3])
df.insert(2, 'z', np.nan)

print df

df.ix[2:, 'z'] = 42

print df

print '\n***EXPECTED\n'

df = DataFrame({'x': [1.1, 2.1, 3.1, 4.1], 'y': [5.1, 6.1, 7.1, 8.1], 'z':[np.nan]*4}, index=[0,1,2,3])

print df

df.ix[2:, 'z'] = 42

print df

The output I get is


***RESULT

   x    y    z  
0  1.1  5.1  NaN
1  2.1  6.1  NaN
2  3.1  7.1  NaN
3  4.1  8.1  NaN
   x    y    z  
0  1.1  5.1  NaN
1  2.1  6.1  NaN
2  3.1  7.1  NaN
3  4.1  8.1  NaN

***EXPECTED

   x    y    z  
0  1.1  5.1  NaN
1  2.1  6.1  NaN
2  3.1  7.1  NaN
3  4.1  8.1  NaN
   x    y    z   
0  1.1  5.1  NaN 
1  2.1  6.1  NaN 
2  3.1  7.1  42
3  4.1  8.1  42
@wesm

This comment has been minimized.

Copy link
Member

commented Oct 28, 2011

thanks for catching this. fixed in the above commit

@wesm wesm closed this Oct 28, 2011

@Komnomnomnom

This comment has been minimized.

Copy link
Contributor Author

commented Oct 28, 2011

Awesome, thanks Wes.

yarikoptic added a commit to neurodebian/pandas that referenced this issue Nov 2, 2011
Merge commit 'v0.5.0-7-gcf32be2' into debian
* commit 'v0.5.0-7-gcf32be2': (161 commits)
  ENH: add melt function, speed up DataFrame.apply
  DOC: release notes re: GH pandas-dev#304
  BUG: clear Series caches on consolidation, address GH pandas-dev#304
  DOC: fix exceptions in docs
  ENH: cython count_level function, cleanup and tests
  DOC: update release note
  BUG: fix DataFrame.to_csv bug described in GH pandas-dev#290
  RLS: Version 0.5.0
  BLD: another 2to3 fix
  BLD: docstring fixes to suppress 2to3 warnings
  BUG: handle negative indices extending before beginning of Series
  TST: fix test case broken by last change
  BUG: don't be too aggressive with int conversion parsing MultiIndex, GH pandas-dev#285
  BUG: missed one
  BUG: workaround not being able to use cast=True with boolean dtype in Python 2.5
  TST: tuples and strings aren't comparable in python 3
  TST: more 32-bit integer fussiness
  ENH: -> int64 everywhere
  TST: int64 fixes
  TST: 32-bit use 64-bit integer
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.