pydata/pandas — pull request #3977 by jreback (2013-06-21 00:00:43+00:00)
Title: BUG: Possibly invalidate the item_cache when numpy implicty converts a v...

closes #3970

``df['bb'].iloc[0] = 0.13``
here ``bb`` is put into the ``_item_cache`` and the first element assigned 0.13; ``bb`` is still a view onto the frame block

``df_tmp = df.iloc[[True]*len(df)]``
``df_tmp`` is now a copy of df, but built up as a take block-by-block from ``df``. I believe numpy then decides to invalidate the views to the memory in the float block (why I have no idea); ``bb`` in ``df`` is still holding the view in the `_item_cache` to the old memory location.

``df['bb'].iloc[0] = 0.15``
grabs ``bb`` from the cache and assigns 0.15 to it, BUT it is not longer a view onto the float block in ``df`` so nothing appears to get updated

I tried 2 fixes:

1) when getting an item from the ``_item_cache`` check if its a view of the underlying data - this works, but makes lookups way slow
2) clear the cache when ``taking`` ON THE ORIGINAL frame, so future lookups will cache-miss and get the correct data from the block manager

Fundamentally we COULD do this in the first statement ``df['bb'].iloc[0] = 0.13``, where we don't reset the cache, except we don't have a reference to df (well we do, but by the time the operation is carried out we have an operation on the series, so have lost the frame reference)

So this is fixed in this case, but not sure what other numpy ops implicity convert view-> copy (and we are holding onto the cached view).