Skip to content

Commit c3ac291

Browse files
DEPR: Series ndarray properties (strides, data, base, itemsize, flags)
1 parent 6245e8c commit c3ac291

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

pandas/core/base.py

+15
Original file line numberDiff line numberDiff line change
@@ -737,11 +737,17 @@ def item(self):
737737
@property
738738
def data(self):
739739
""" return the data pointer of the underlying data """
740+
warnings.warn("Series/Index.data is deprecated and will be "
741+
"removed in a future version",
742+
FutureWarning, stacklevel=2)
740743
return self.values.data
741744

742745
@property
743746
def itemsize(self):
744747
""" return the size of the dtype of the item of the underlying data """
748+
warnings.warn("Series/Index.itemsize is deprecated and will be "
749+
"removed in a future version",
750+
FutureWarning, stacklevel=2)
745751
return self._ndarray_values.itemsize
746752

747753
@property
@@ -752,6 +758,9 @@ def nbytes(self):
752758
@property
753759
def strides(self):
754760
""" return the strides of the underlying data """
761+
warnings.warn("Series/Index.strides is deprecated and will be "
762+
"removed in a future version",
763+
FutureWarning, stacklevel=2)
755764
return self._ndarray_values.strides
756765

757766
@property
@@ -762,13 +771,19 @@ def size(self):
762771
@property
763772
def flags(self):
764773
""" return the ndarray.flags for the underlying data """
774+
warnings.warn("Series/Index.flags is deprecated and will be "
775+
"removed in a future version",
776+
FutureWarning, stacklevel=2)
765777
return self.values.flags
766778

767779
@property
768780
def base(self):
769781
""" return the base object if the memory of the underlying data is
770782
shared
771783
"""
784+
warnings.warn("Series/Index.base is deprecated and will be "
785+
"removed in a future version",
786+
FutureWarning, stacklevel=2)
772787
return self.values.base
773788

774789
@property

pandas/core/indexes/datetimelike.py

+10
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,16 @@ def ceil(self, freq):
209209
class DatetimeIndexOpsMixin(object):
210210
""" common ops mixin to support a unified interface datetimelike Index """
211211

212+
@property
213+
def base(self):
214+
""" return the base object if the memory of the underlying data is
215+
shared
216+
"""
217+
# override deprecated property in IndexOpsMixin, as we still need
218+
# this for internals (DatetimeIndex/TimedeltaIndex is stored as
219+
# values in Blocks)
220+
return self.values.base
221+
212222
def equals(self, other):
213223
"""
214224
Determines if two Index objects contain the same elements.

pandas/tests/test_base.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from pandas.core.base import PandasObject, NoNewAttributesMixin
2323
from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin
2424
from pandas._libs.tslib import iNaT
25+
import pandas.util.testing as tm
2526

2627

2728
class CheckStringMixin(object):
@@ -316,16 +317,25 @@ def test_ndarray_compat_properties(self):
316317

317318
for o in self.objs:
318319
# Check that we work.
319-
for p in ['shape', 'dtype', 'flags', 'T',
320-
'strides', 'itemsize', 'nbytes']:
320+
for p in ['shape', 'dtype', 'T', 'nbytes']:
321321
assert getattr(o, p, None) is not None
322322

323-
assert hasattr(o, 'base')
323+
# deprecated properties
324+
for p in ['flags', 'strides', 'itemsize']:
325+
with tm.assert_produces_warning(FutureWarning):
326+
assert getattr(o, p, None) is not None
327+
328+
# not deprecated for datetime-like indices because they are used
329+
# inside blocks
330+
if not isinstance(o, (DatetimeIndex, TimedeltaIndex, PeriodIndex)):
331+
with tm.assert_produces_warning(FutureWarning):
332+
assert hasattr(o, 'base')
324333

325334
# If we have a datetime-like dtype then needs a view to work
326335
# but the user is responsible for that
327336
try:
328-
assert o.data is not None
337+
with tm.assert_produces_warning(FutureWarning):
338+
assert o.data is not None
329339
except ValueError:
330340
pass
331341

0 commit comments

Comments
 (0)