Note that there are some explanatory texts on larger screens.

plurals
  1. POpandas DataFrame combine_first and update methods have strange behavior
    primarykey
    data
    text
    <p>I'm running into a strange issue (or intended?) where <code>combine_first</code> or <code>update</code> are causing values stored as <code>bool</code> to be upcasted into <code>float64</code>s if the argument supplied is not supplying the boolean columns.</p> <p>Example workflow in ipython:</p> <pre><code>In [144]: test = pd.DataFrame([[1,2,False,True],[4,5,True,False]], columns=['a','b','isBool', 'isBool2']) In [145]: test Out[145]: a b isBool isBool2 0 1 2 False True 1 4 5 True False In [147]: b = pd.DataFrame([[45,45]], index=[0], columns=['a','b']) In [148]: b Out[148]: a b 0 45 45 In [149]: test.update(b) In [150]: test Out[150]: a b isBool isBool2 0 45 45 0 1 1 4 5 1 0 </code></pre> <p>Was this meant to be the behavior of the <code>update</code> function? I would think that if nothing was specified that <code>update</code> wouldn't mess with the other columns.</p> <hr> <p><strong>EDIT</strong>: I started tinkering around a little more. The plot thickens. If I insert one more command: <code>test.update([])</code> before running <code>test.update(b)</code>, boolean behavior works at the cost of numbers upcasted as <code>objects</code>. This also applies to DSM's simplified example.</p> <p>Based on <a href="https://github.com/pydata/pandas/blob/master/pandas/core/frame.py#L3830" rel="nofollow">panda's source code</a>, it looks like the reindex_like method is creating a DataFrame of dtype <code>object</code>, while reindex_like <code>b</code> creates a DataFrame of dtype <code>float64</code>. Since <code>object</code> is more general, subsequent operations work with bools. Unfortunately running <code>np.log</code> on the numerical columns will fail with an <code>AttributeError</code>. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload