From 6253fff460e4a618d323b04aa42c7be5e2efc539 Mon Sep 17 00:00:00 2001 From: Daniel Kirkham Date: Thu, 8 Sep 2016 16:37:05 +0100 Subject: [PATCH 1/2] Fix _assert_shared --- lib/iris/pandas.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/iris/pandas.py b/lib/iris/pandas.py index 67a651a42a..15a9da6f48 100644 --- a/lib/iris/pandas.py +++ b/lib/iris/pandas.py @@ -1,4 +1,4 @@ -# (C) British Crown Copyright 2013 - 2015, Met Office +# (C) British Crown Copyright 2013 - 2016, Met Office # # This file is part of Iris. # @@ -129,6 +129,9 @@ def _assert_shared(np_obj, pandas_obj): base = pandas_obj.base else: base = pandas_obj[0].base + + if pandas_obj.values is np_obj: + return # Chase the stack of NumPy `base` references back to see if any of # them are our original array. while base is not None: From aaa8c044ff88424944d3f71ca58cd0ae35f8b64d Mon Sep 17 00:00:00 2001 From: Daniel Kirkham Date: Wed, 14 Sep 2016 11:50:08 +0100 Subject: [PATCH 2/2] Modify fix and add dev comment --- lib/iris/pandas.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/iris/pandas.py b/lib/iris/pandas.py index 15a9da6f48..26ce5c5432 100644 --- a/lib/iris/pandas.py +++ b/lib/iris/pandas.py @@ -130,8 +130,14 @@ def _assert_shared(np_obj, pandas_obj): else: base = pandas_obj[0].base - if pandas_obj.values is np_obj: - return + # 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 + # Chase the stack of NumPy `base` references back to see if any of # them are our original array. while base is not None: