diff --git a/pandas/core/base.py b/pandas/core/base.py index 0d55fa8b97aae..5a9711391c7c8 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -737,11 +737,17 @@ def item(self): @property def data(self): """ return the data pointer of the underlying data """ + warnings.warn("Series/Index.data is deprecated and will be " + "removed in a future version", + FutureWarning, stacklevel=2) return self.values.data @property def itemsize(self): """ return the size of the dtype of the item of the underlying data """ + warnings.warn("Series/Index.itemsize is deprecated and will be " + "removed in a future version", + FutureWarning, stacklevel=2) return self._ndarray_values.itemsize @property @@ -752,6 +758,9 @@ def nbytes(self): @property def strides(self): """ return the strides of the underlying data """ + warnings.warn("Series/Index.strides is deprecated and will be " + "removed in a future version", + FutureWarning, stacklevel=2) return self._ndarray_values.strides @property @@ -762,6 +771,9 @@ def size(self): @property def flags(self): """ return the ndarray.flags for the underlying data """ + warnings.warn("Series/Index.flags is deprecated and will be " + "removed in a future version", + FutureWarning, stacklevel=2) return self.values.flags @property @@ -769,6 +781,9 @@ def base(self): """ return the base object if the memory of the underlying data is shared """ + warnings.warn("Series/Index.base is deprecated and will be " + "removed in a future version", + FutureWarning, stacklevel=2) return self.values.base @property diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 95e1f8438c704..432c1c67cb86c 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -209,6 +209,16 @@ def ceil(self, freq): class DatetimeIndexOpsMixin(object): """ common ops mixin to support a unified interface datetimelike Index """ + @property + def base(self): + """ return the base object if the memory of the underlying data is + shared + """ + # override deprecated property in IndexOpsMixin, as we still need + # this for internals (DatetimeIndex/TimedeltaIndex is stored as + # values in Blocks) + return self.values.base + def equals(self, other): """ Determines if two Index objects contain the same elements. diff --git a/pandas/tests/test_base.py b/pandas/tests/test_base.py index c4c02c0bf6f17..9a7157dd06b25 100644 --- a/pandas/tests/test_base.py +++ b/pandas/tests/test_base.py @@ -22,6 +22,7 @@ from pandas.core.base import PandasObject, NoNewAttributesMixin from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin from pandas._libs.tslib import iNaT +import pandas.util.testing as tm class CheckStringMixin(object): @@ -316,16 +317,25 @@ def test_ndarray_compat_properties(self): for o in self.objs: # Check that we work. - for p in ['shape', 'dtype', 'flags', 'T', - 'strides', 'itemsize', 'nbytes']: + for p in ['shape', 'dtype', 'T', 'nbytes']: assert getattr(o, p, None) is not None - assert hasattr(o, 'base') + # deprecated properties + for p in ['flags', 'strides', 'itemsize']: + with tm.assert_produces_warning(FutureWarning): + assert getattr(o, p, None) is not None + + # not deprecated for datetime-like indices because they are used + # inside blocks + if not isinstance(o, (DatetimeIndex, TimedeltaIndex, PeriodIndex)): + with tm.assert_produces_warning(FutureWarning): + assert hasattr(o, 'base') # If we have a datetime-like dtype then needs a view to work # but the user is responsible for that try: - assert o.data is not None + with tm.assert_produces_warning(FutureWarning): + assert o.data is not None except ValueError: pass