From 93972dc1fb28ddcebb9c86a7b8ce6cd9a39f60ff Mon Sep 17 00:00:00 2001 From: pilkibun Date: Sat, 15 Jun 2019 07:35:36 +0300 Subject: [PATCH 1/2] CLN: In DecimalArray implement aliases as properties Much safer, since _data may be assigned to --- pandas/tests/extension/decimal/array.py | 26 +++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/pandas/tests/extension/decimal/array.py b/pandas/tests/extension/decimal/array.py index 3b95c8d919eb1..e64ccce52c2c9 100644 --- a/pandas/tests/extension/decimal/array.py +++ b/pandas/tests/extension/decimal/array.py @@ -59,14 +59,28 @@ def __init__(self, values, dtype=None, copy=False, context=None): values = np.asarray(values, dtype=object) self._data = values - # Some aliases for common attribute names to ensure pandas supports - # these - self._items = self.data = self._data - # those aliases are currently not working due to assumptions - # in internal code (GH-20735) - # self._values = self.values = self.data self._dtype = DecimalDtype(context) + # aliases for common attribute names, to ensure pandas supports these + @property + def _items(self): + return self._data + + @property + def data(self): + return self._data + + # those aliases are currently not working due to assumptions + # in internal code (GH-20735) + # @property + # def _values(self): + # return self._data + + # @property + # def values(self): + # return self._data + # end aliases + @property def dtype(self): return self._dtype From 914840abc8e8e2c08d20dd27856928bc49d9080f Mon Sep 17 00:00:00 2001 From: pilkibun Date: Wed, 19 Jun 2019 10:08:29 +0300 Subject: [PATCH 2/2] Improve comment --- pandas/tests/extension/decimal/array.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/tests/extension/decimal/array.py b/pandas/tests/extension/decimal/array.py index e64ccce52c2c9..aa53489ab7d4d 100644 --- a/pandas/tests/extension/decimal/array.py +++ b/pandas/tests/extension/decimal/array.py @@ -61,7 +61,9 @@ def __init__(self, values, dtype=None, copy=False, context=None): self._data = values self._dtype = DecimalDtype(context) - # aliases for common attribute names, to ensure pandas supports these + # Certain pandas function currently refer to these attributes + # expecting them to return a numpy array of values. here we + # just treat them as synonyms for `self._data`. @property def _items(self): return self._data