DataFrame.cumsum() breaks when using a DataFrame that was filled using the isnan() function · Issue #5103 · pandas-dev/pandas (original) (raw)

Most help documents I've seen suggest using the fillna() function to fill a DataFrame. However, if you try to use the results of that fill operation with other functions, it can break. For example, the following code:

df = DataFrame(index=["A","B","C"], columns = [1,2,3,4,5]) df2 = df.fillna(1) df2.cumsum()

Fails with the following error message:

 File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/pandas/core/generic.py", line 827, in cumsum
    mask = np.isnan(self.values)
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

However, creating a DataFrame filled with ones using the following works just fine:

df = DataFrame(np.ones((3,5)),index=["A","B","C"], columns = [1,2,3,4,5])