Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: remove itemsize, data, base, flags, strides #29918

Merged
merged 5 commits into from
Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
- Changed the default value for the `raw` argument in :func:`Series.rolling().apply() <pandas.core.window.Rolling.apply>`, :func:`DataFrame.rolling().apply() <pandas.core.window.Rolling.apply>`,
- :func:`Series.expanding().apply() <pandas.core.window.Expanding.apply>`, and :func:`DataFrame.expanding().apply() <pandas.core.window.Expanding.apply>` to ``False`` (:issue:`20584`)
- Removed previously deprecated :attr:`Timestamp.weekday_name`, :attr:`DatetimeIndex.weekday_name`, and :attr:`Series.dt.weekday_name` (:issue:`18164`)
-
- Removed the previously deprecated :attr:`Series.base`, :attr:`Index.base`, :attr:`Categorical.base`, :attr:`Series.flags`, :attr:`Index.flags`, :attr:`PeriodArray.flags`, :attr:`Series.strides`, :attr:`Index.strides`, :attr:`Series.itemsize`, :attr:`Index.itemsize`, :attr:`Series.data`, :attr:`Index.data` (:issue:`20721`)

.. _whatsnew_1000.performance:

Expand Down
7 changes: 0 additions & 7 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,6 @@ def tolist(self) -> list:

to_list = tolist

@property
def base(self) -> None:
"""
compat, we are always our own object
"""
return None

@classmethod
def _from_inferred_categories(
cls, inferred_categories, inferred_codes, dtype, true_values=None
Expand Down
8 changes: 0 additions & 8 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,14 +618,6 @@ def astype(self, dtype, copy=True):
return self.asfreq(dtype.freq)
return super().astype(dtype, copy=copy)

@property
def flags(self):
# TODO: remove
# We need this since reduction.SeriesBinGrouper uses values.flags
# Ideally, we wouldn't be passing objects down there in the first
# place.
return self._data.flags

# ------------------------------------------------------------------
# Arithmetic Methods
_create_comparison_method = classmethod(_period_array_cmp)
Expand Down
97 changes: 4 additions & 93 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from collections import OrderedDict
import textwrap
from typing import Dict, FrozenSet, List, Optional
import warnings

import numpy as np

Expand Down Expand Up @@ -628,15 +627,7 @@ class IndexOpsMixin:
# ndarray compatibility
__array_priority__ = 1000
_deprecations: FrozenSet[str] = frozenset(
[
"tolist", # tolist is not deprecated, just suppressed in the __dir__
"base",
"data",
"item",
"itemsize",
"flags",
"strides",
]
["tolist"] # tolist is not deprecated, just suppressed in the __dir__
)

def transpose(self, *args, **kwargs):
Expand Down Expand Up @@ -693,49 +684,14 @@ def item(self):
"""
Return the first element of the underlying data as a python scalar.

.. deprecated:: 0.25.0

Returns
-------
scalar
The first element of %(klass)s.
"""
warnings.warn(
"`item` has been deprecated and will be removed in a future version",
FutureWarning,
stacklevel=2,
)
return self.values.item()

@property
def data(self):
"""
Return the data pointer of the underlying data.

.. deprecated:: 0.23.0
"""
warnings.warn(
"{obj}.data is deprecated and will be removed "
"in a future version".format(obj=type(self).__name__),
FutureWarning,
stacklevel=2,
)
return self.values.data

@property
def itemsize(self):
"""
Return the size of the dtype of the item of the underlying data.

.. deprecated:: 0.23.0
"""
warnings.warn(
"{obj}.itemsize is deprecated and will be removed "
"in a future version".format(obj=type(self).__name__),
FutureWarning,
stacklevel=2,
)
return self._ndarray_values.itemsize
if len(self) == 1:
return next(iter(self))
jbrockmendel marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError("can only convert an array of size 1 to a Python scalar")

@property
def nbytes(self):
Expand All @@ -744,58 +700,13 @@ def nbytes(self):
"""
return self._values.nbytes

@property
def strides(self):
"""
Return the strides of the underlying data.

.. deprecated:: 0.23.0
"""
warnings.warn(
"{obj}.strides is deprecated and will be removed "
"in a future version".format(obj=type(self).__name__),
FutureWarning,
stacklevel=2,
)
return self._ndarray_values.strides

@property
def size(self):
"""
Return the number of elements in the underlying data.
"""
return len(self._values)

@property
def flags(self):
"""
Return the ndarray.flags for the underlying data.

.. deprecated:: 0.23.0
"""
warnings.warn(
"{obj}.flags is deprecated and will be removed "
"in a future version".format(obj=type(self).__name__),
FutureWarning,
stacklevel=2,
)
return self.values.flags

@property
def base(self):
"""
Return the base object if the memory of the underlying data is shared.

.. deprecated:: 0.23.0
"""
warnings.warn(
"{obj}.base is deprecated and will be removed "
"in a future version".format(obj=type(self).__name__),
FutureWarning,
stacklevel=2,
)
return self.values.base

@property
def array(self) -> ExtensionArray:
"""
Expand Down
14 changes: 0 additions & 14 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from operator import le, lt
import textwrap
from typing import Any, Optional, Tuple, Union
import warnings

import numpy as np

Expand Down Expand Up @@ -455,19 +454,6 @@ def size(self):
# Avoid materializing ndarray[Interval]
return self._data.size

@property
def itemsize(self):
msg = (
"IntervalIndex.itemsize is deprecated and will be removed in "
"a future version"
)
warnings.warn(msg, FutureWarning, stacklevel=2)

# suppress the warning from the underlying left/right itemsize
with warnings.catch_warnings():
warnings.simplefilter("ignore")
return self.left.itemsize + self.right.itemsize

def __len__(self) -> int:
return len(self.left)

Expand Down
47 changes: 1 addition & 46 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,62 +911,17 @@ def __setstate__(self, state):

_unpickle_compat = __setstate__

@property
def flags(self):
""" return the ndarray.flags for the underlying data """
warnings.warn(
"{obj}.flags is deprecated and will be removed "
"in a future version".format(obj=type(self).__name__),
FutureWarning,
stacklevel=2,
)
return self._ndarray_values.flags

def item(self):
"""
return the first element of the underlying data as a python
scalar

.. deprecated:: 0.25.0

Return the first element of the underlying data as a python scalar.
"""
warnings.warn(
"`item` has been deprecated and will be removed in a future version",
FutureWarning,
stacklevel=2,
)
# TODO(DatetimeArray): remove
if len(self) == 1:
return self[0]
else:
# TODO: is this still necessary?
# copy numpy's message here because Py26 raises an IndexError
raise ValueError("can only convert an array of size 1 to a Python scalar")

@property
def data(self):
""" return the data pointer of the underlying data """
warnings.warn(
"{obj}.data is deprecated and will be removed "
"in a future version".format(obj=type(self).__name__),
FutureWarning,
stacklevel=2,
)
return np.asarray(self._data).data

@property
def base(self):
""" return the base object if the memory of the underlying data is
shared
"""
warnings.warn(
"{obj}.base is deprecated and will be removed "
"in a future version".format(obj=type(self).__name__),
FutureWarning,
stacklevel=2,
)
return np.asarray(self._data)

def memory_usage(self, deep=False):
result = super().memory_usage(deep=deep)
if hasattr(self, "_cache") and "_int64index" in self._cache:
Expand Down
11 changes: 0 additions & 11 deletions pandas/tests/indexes/interval/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,17 +836,6 @@ def test_nbytes(self):
expected = 64 # 4 * 8 * 2
assert result == expected

def test_itemsize(self):
# GH 19209
left = np.arange(0, 4, dtype="i8")
right = np.arange(1, 5, dtype="i8")
expected = 16 # 8 * 2

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
result = IntervalIndex.from_arrays(left, right).itemsize

assert result == expected

@pytest.mark.parametrize("new_closed", ["left", "right", "both", "neither"])
def test_set_closed(self, name, closed, new_closed):
# GH 21670
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/indexes/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,10 @@ def test_ensure_copied_data(self, indices):
# Index.__new__ is honored.
#
# Must be tested separately from other indexes because
# self.value is not an ndarray.
_base = lambda ar: ar if ar.base is None else ar.base
# self.values is not an ndarray.
# GH#????? Index.base has been removed
# FIXME: is this test still meaningful?
_base = lambda ar: ar if getattr(ar, "base", None) is None else ar.base

result = CategoricalIndex(indices.values, copy=True)
tm.assert_index_equal(indices, result)
Expand Down
9 changes: 4 additions & 5 deletions pandas/tests/series/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,10 @@ def f(x):
tm.assert_series_equal(result, expected)

# .item()
with tm.assert_produces_warning(FutureWarning):
s = Series([1])
result = s.item()
assert result == 1
assert s.item() == s.iloc[0]
s = Series([1])
result = s.item()
assert result == 1
assert s.item() == s.iloc[0]

# using an ndarray like function
s = Series(np.random.randn(10))
Expand Down
24 changes: 5 additions & 19 deletions pandas/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,31 +333,17 @@ def test_ndarray_compat_properties(self):
assert getattr(o, p, None) is not None

# deprecated properties
for p in ["flags", "strides", "itemsize"]:
with tm.assert_produces_warning(FutureWarning):
assert getattr(o, p, None) is not None

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:
with tm.assert_produces_warning(FutureWarning):
assert o.data is not None
except ValueError:
pass
for p in ["flags", "strides", "itemsize", "base", "data"]:
assert not hasattr(o, p)

with pytest.raises(ValueError):
with tm.assert_produces_warning(FutureWarning):
o.item() # len > 1
o.item() # len > 1

assert o.ndim == 1
assert o.size == len(o)

with tm.assert_produces_warning(FutureWarning):
assert Index([1]).item() == 1
assert Series([1]).item() == 1
assert Index([1]).item() == 1
assert Series([1]).item() == 1

def test_value_counts_unique_nunique(self):
for orig in self.objs:
Expand Down