Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions lib/iris/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,26 +130,15 @@ def _as_pandas_coord(coord):

def _assert_shared(np_obj, pandas_obj):
"""Ensure the pandas object shares memory."""
if hasattr(pandas_obj, 'base'):
base = pandas_obj.base
else:
base = pandas_obj[0].base

# Prior to Pandas 0.17, when pandas_obj is a Series, pandas_obj.values
# returns a view of the underlying array, and pandas_obj.base, which calls
# pandas_obj.values.base, returns the underlying array. In 0.17 and 0.18
# pandas_obj.values returns the underlying array, so base may be None even
# if the array is shared.
if base is None:
base = pandas_obj.values
values = pandas_obj.values

def _get_base(array):
# Chase the stack of NumPy `base` references back to the original array
while array.base is not None:
array = array.base
return array

base = _get_base(base)
base = _get_base(values)
np_base = _get_base(np_obj)
if base is not np_base:
msg = ('Pandas {} does not share memory'
Expand Down