Skip to content

Commit

Permalink
DEPR: Series ndarray properties (strides, data, base, itemsize, flags)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Apr 17, 2018
1 parent 6245e8c commit c3ac291
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
15 changes: 15 additions & 0 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -762,13 +771,19 @@ 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
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
Expand Down
10 changes: 10 additions & 0 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 14 additions & 4 deletions pandas/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit c3ac291

Please sign in to comment.