From 00fe4878192f624f8f766f4ef0364605cd76ab69 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Thu, 5 Dec 2019 17:43:05 -0800 Subject: [PATCH 1/5] DEPR: Index.contains, RangeIndex._start, _stop, _step --- doc/source/whatsnew/v1.0.0.rst | 2 + pandas/core/indexes/base.py | 20 --------- pandas/core/indexes/datetimes.py | 28 ------------- pandas/core/indexes/range.py | 48 ---------------------- pandas/tests/indexes/datetimes/test_ops.py | 12 ------ pandas/tests/indexes/test_base.py | 8 ++-- pandas/tests/indexes/test_range.py | 15 ------- 7 files changed, 6 insertions(+), 127 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 5e2eaa6ca4a94..65b3278036178 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -546,6 +546,8 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. - Removed support for nested renaming in :meth:`DataFrame.aggregate`, :meth:`Series.aggregate`, :meth:`DataFrameGroupBy.aggregate`, :meth:`SeriesGroupBy.aggregate`, :meth:`Rolling.aggregate` (:issue:`18529`) - Passing ``datetime64`` data to :class:`TimedeltaIndex` or ``timedelta64`` data to ``DatetimeIndex`` now raises ``TypeError`` (:issue:`23539`, :issue:`23937`) - A tuple passed to :meth:`DataFrame.groupby` is now exclusively treated as a single key (:issue:`18314`) +- Removed the previously deprecated :meth:`Index.contains`, use ``key in index`` instead (:issue:`?????`) +- Removed the previously deprecated :attr:`RangeIndex._start`, :attr:`RangeIndex._stop`, :atttr:`RangeIndex._step` (:issue:`26581`) - Removed :meth:`Series.from_array` (:issue:`18258`) - Removed :meth:`DataFrame.from_items` (:issue:`18458`) - Removed :meth:`DataFrame.as_matrix`, :meth:`Series.as_matrix` (:issue:`18458`) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index e57ec40bdf04d..1587d97ffb52c 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -3994,26 +3994,6 @@ def __contains__(self, key) -> bool: except (OverflowError, TypeError, ValueError): return False - def contains(self, key) -> bool: - """ - Return a boolean indicating whether the provided key is in the index. - - .. deprecated:: 0.25.0 - Use ``key in index`` instead of ``index.contains(key)``. - - Returns - ------- - bool - """ - warnings.warn( - "The 'contains' method is deprecated and will be removed in a " - "future version. Use 'key in index' instead of " - "'index.contains(key)'", - FutureWarning, - stacklevel=2, - ) - return key in self - def __hash__(self): raise TypeError(f"unhashable type: {repr(type(self).__name__)}") diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index cef8155f0bfa3..85ab8c22ca0cd 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1147,34 +1147,6 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None): _has_same_tz = ea_passthrough(DatetimeArray._has_same_tz) - @property - def offset(self): - """ - get/set the frequency of the instance - """ - msg = ( - "{cls}.offset has been deprecated and will be removed " - "in a future version; use {cls}.freq instead.".format( - cls=type(self).__name__ - ) - ) - warnings.warn(msg, FutureWarning, stacklevel=2) - return self.freq - - @offset.setter - def offset(self, value): - """ - get/set the frequency of the instance - """ - msg = ( - "{cls}.offset has been deprecated and will be removed " - "in a future version; use {cls}.freq instead.".format( - cls=type(self).__name__ - ) - ) - warnings.warn(msg, FutureWarning, stacklevel=2) - self._data.freq = value - def __getitem__(self, key): result = self._data.__getitem__(key) if is_scalar(result): diff --git a/pandas/core/indexes/range.py b/pandas/core/indexes/range.py index f300cde3b5bcc..d4af3626cfa85 100644 --- a/pandas/core/indexes/range.py +++ b/pandas/core/indexes/range.py @@ -2,7 +2,6 @@ import operator from sys import getsizeof from typing import Optional, Union -import warnings import numpy as np @@ -215,21 +214,6 @@ def start(self): # GH 25710 return self._range.start - @property - def _start(self): - """ - The value of the `start` parameter (``0`` if this was not supplied). - - .. deprecated:: 0.25.0 - Use ``start`` instead. - """ - warnings.warn( - self._deprecation_message.format("_start", "start"), - DeprecationWarning, - stacklevel=2, - ) - return self.start - @cache_readonly def stop(self): """ @@ -237,22 +221,6 @@ def stop(self): """ return self._range.stop - @property - def _stop(self): - """ - The value of the `stop` parameter. - - .. deprecated:: 0.25.0 - Use ``stop`` instead. - """ - # GH 25710 - warnings.warn( - self._deprecation_message.format("_stop", "stop"), - DeprecationWarning, - stacklevel=2, - ) - return self.stop - @cache_readonly def step(self): """ @@ -261,22 +229,6 @@ def step(self): # GH 25710 return self._range.step - @property - def _step(self): - """ - The value of the `step` parameter (``1`` if this was not supplied). - - .. deprecated:: 0.25.0 - Use ``step`` instead. - """ - # GH 25710 - warnings.warn( - self._deprecation_message.format("_step", "step"), - DeprecationWarning, - stacklevel=2, - ) - return self.step - @cache_readonly def nbytes(self) -> int: """ diff --git a/pandas/tests/indexes/datetimes/test_ops.py b/pandas/tests/indexes/datetimes/test_ops.py index c9c5963e5590c..67dad61611b20 100644 --- a/pandas/tests/indexes/datetimes/test_ops.py +++ b/pandas/tests/indexes/datetimes/test_ops.py @@ -437,18 +437,6 @@ def test_freq_setter_errors(self): with pytest.raises(ValueError, match="Invalid frequency"): idx._data.freq = "foo" - def test_offset_deprecated(self): - # GH 20716 - idx = pd.DatetimeIndex(["20180101", "20180102"]) - - # getter deprecated - with tm.assert_produces_warning(FutureWarning): - idx.offset - - # setter deprecated - with tm.assert_produces_warning(FutureWarning): - idx.offset = BDay() - class TestBusinessDatetimeIndex: def setup_method(self, method): diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index e62d50f64d8ff..891fed21cfb8c 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -2405,10 +2405,10 @@ def test_tab_complete_warning(self, ip): with provisionalcompleter("ignore"): list(ip.Completer.completions("idx.", 4)) - def test_deprecated_contains(self, indices): - # deprecated for all types except IntervalIndex - warning = FutureWarning if not isinstance(indices, pd.IntervalIndex) else None - with tm.assert_produces_warning(warning): + def test_contains_method_removed(self, indices): + # method removed for all types except IntervalIndex + err = AttributeError if not isinstance(indices, pd.IntervalIndex) else None + with pytest.raises(err): indices.contains(1) diff --git a/pandas/tests/indexes/test_range.py b/pandas/tests/indexes/test_range.py index b60d3126da1d5..1155ead294319 100644 --- a/pandas/tests/indexes/test_range.py +++ b/pandas/tests/indexes/test_range.py @@ -205,13 +205,6 @@ def test_start_stop_step_attrs(self, index, start, stop, step): assert index.stop == stop assert index.step == step - @pytest.mark.parametrize("attr_name", ["_start", "_stop", "_step"]) - def test_deprecated_start_stop_step_attrs(self, attr_name): - # GH 26581 - idx = self.create_index() - with tm.assert_produces_warning(DeprecationWarning): - getattr(idx, attr_name) - def test_copy(self): i = RangeIndex(5, name="Foo") i_copy = i.copy() @@ -306,14 +299,6 @@ def test_cached_data(self): 91 in idx assert idx._cached_data is None - with tm.assert_produces_warning(FutureWarning): - idx.contains(90) - assert idx._cached_data is None - - with tm.assert_produces_warning(FutureWarning): - idx.contains(91) - assert idx._cached_data is None - idx.all() assert idx._cached_data is None From 0ebfdcf98733c73a573f9efa58873a3b6f823e33 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Thu, 5 Dec 2019 17:44:49 -0800 Subject: [PATCH 2/5] GH ref --- doc/source/whatsnew/v1.0.0.rst | 2 +- pandas/tests/indexes/test_base.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 65b3278036178..128cca8a85a27 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -546,7 +546,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. - Removed support for nested renaming in :meth:`DataFrame.aggregate`, :meth:`Series.aggregate`, :meth:`DataFrameGroupBy.aggregate`, :meth:`SeriesGroupBy.aggregate`, :meth:`Rolling.aggregate` (:issue:`18529`) - Passing ``datetime64`` data to :class:`TimedeltaIndex` or ``timedelta64`` data to ``DatetimeIndex`` now raises ``TypeError`` (:issue:`23539`, :issue:`23937`) - A tuple passed to :meth:`DataFrame.groupby` is now exclusively treated as a single key (:issue:`18314`) -- Removed the previously deprecated :meth:`Index.contains`, use ``key in index`` instead (:issue:`?????`) +- Removed the previously deprecated :meth:`Index.contains`, use ``key in index`` instead (:issue:`30103`) - Removed the previously deprecated :attr:`RangeIndex._start`, :attr:`RangeIndex._stop`, :atttr:`RangeIndex._step` (:issue:`26581`) - Removed :meth:`Series.from_array` (:issue:`18258`) - Removed :meth:`DataFrame.from_items` (:issue:`18458`) diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 891fed21cfb8c..6655e459943e6 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -2406,7 +2406,7 @@ def test_tab_complete_warning(self, ip): list(ip.Completer.completions("idx.", 4)) def test_contains_method_removed(self, indices): - # method removed for all types except IntervalIndex + # GH#30103 method removed for all types except IntervalIndex err = AttributeError if not isinstance(indices, pd.IntervalIndex) else None with pytest.raises(err): indices.contains(1) From 09ab9e9ec1ee5054101b32ede37e859141f7579b Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Thu, 5 Dec 2019 18:29:34 -0800 Subject: [PATCH 3/5] compat fixup --- pandas/tests/indexes/test_base.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 6655e459943e6..18bdb279ebad6 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -2407,9 +2407,11 @@ def test_tab_complete_warning(self, ip): def test_contains_method_removed(self, indices): # GH#30103 method removed for all types except IntervalIndex - err = AttributeError if not isinstance(indices, pd.IntervalIndex) else None - with pytest.raises(err): + if isinstance(indices, pd.IntervalIndex): indices.contains(1) + else: + with pytest.raises(AttributeError): + indices.contains(1) class TestMixedIntIndex(Base): From 24b25d4444749c6fd47356cee5d61aea4e454412 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Thu, 5 Dec 2019 20:14:37 -0800 Subject: [PATCH 4/5] revert _start, _stop, _step --- doc/source/whatsnew/v1.0.0.rst | 1 - pandas/core/indexes/range.py | 48 ++++++++++++++++++++++++++++++ pandas/tests/indexes/test_range.py | 7 +++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 128cca8a85a27..756282b6c0c8c 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -547,7 +547,6 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more. - Passing ``datetime64`` data to :class:`TimedeltaIndex` or ``timedelta64`` data to ``DatetimeIndex`` now raises ``TypeError`` (:issue:`23539`, :issue:`23937`) - A tuple passed to :meth:`DataFrame.groupby` is now exclusively treated as a single key (:issue:`18314`) - Removed the previously deprecated :meth:`Index.contains`, use ``key in index`` instead (:issue:`30103`) -- Removed the previously deprecated :attr:`RangeIndex._start`, :attr:`RangeIndex._stop`, :atttr:`RangeIndex._step` (:issue:`26581`) - Removed :meth:`Series.from_array` (:issue:`18258`) - Removed :meth:`DataFrame.from_items` (:issue:`18458`) - Removed :meth:`DataFrame.as_matrix`, :meth:`Series.as_matrix` (:issue:`18458`) diff --git a/pandas/core/indexes/range.py b/pandas/core/indexes/range.py index d4af3626cfa85..f300cde3b5bcc 100644 --- a/pandas/core/indexes/range.py +++ b/pandas/core/indexes/range.py @@ -2,6 +2,7 @@ import operator from sys import getsizeof from typing import Optional, Union +import warnings import numpy as np @@ -214,6 +215,21 @@ def start(self): # GH 25710 return self._range.start + @property + def _start(self): + """ + The value of the `start` parameter (``0`` if this was not supplied). + + .. deprecated:: 0.25.0 + Use ``start`` instead. + """ + warnings.warn( + self._deprecation_message.format("_start", "start"), + DeprecationWarning, + stacklevel=2, + ) + return self.start + @cache_readonly def stop(self): """ @@ -221,6 +237,22 @@ def stop(self): """ return self._range.stop + @property + def _stop(self): + """ + The value of the `stop` parameter. + + .. deprecated:: 0.25.0 + Use ``stop`` instead. + """ + # GH 25710 + warnings.warn( + self._deprecation_message.format("_stop", "stop"), + DeprecationWarning, + stacklevel=2, + ) + return self.stop + @cache_readonly def step(self): """ @@ -229,6 +261,22 @@ def step(self): # GH 25710 return self._range.step + @property + def _step(self): + """ + The value of the `step` parameter (``1`` if this was not supplied). + + .. deprecated:: 0.25.0 + Use ``step`` instead. + """ + # GH 25710 + warnings.warn( + self._deprecation_message.format("_step", "step"), + DeprecationWarning, + stacklevel=2, + ) + return self.step + @cache_readonly def nbytes(self) -> int: """ diff --git a/pandas/tests/indexes/test_range.py b/pandas/tests/indexes/test_range.py index 1155ead294319..13b8ca2a8ea22 100644 --- a/pandas/tests/indexes/test_range.py +++ b/pandas/tests/indexes/test_range.py @@ -205,6 +205,13 @@ def test_start_stop_step_attrs(self, index, start, stop, step): assert index.stop == stop assert index.step == step + @pytest.mark.parametrize("attr_name", ["_start", "_stop", "_step"]) + def test_deprecated_start_stop_step_attrs(self, attr_name): + # GH 26581 + idx = self.create_index() + with tm.assert_produces_warning(DeprecationWarning): + getattr(idx, attr_name) + def test_copy(self): i = RangeIndex(5, name="Foo") i_copy = i.copy() From 92381885c01ca9bd55806381fdf7e4cb120691a4 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Thu, 5 Dec 2019 20:36:56 -0800 Subject: [PATCH 5/5] update docs --- doc/redirects.csv | 1 - doc/source/reference/indexing.rst | 1 - 2 files changed, 2 deletions(-) diff --git a/doc/redirects.csv b/doc/redirects.csv index 1471bfb82c07c..e0ec3bcaa340d 100644 --- a/doc/redirects.csv +++ b/doc/redirects.csv @@ -618,7 +618,6 @@ generated/pandas.Index.asi8,../reference/api/pandas.Index.asi8 generated/pandas.Index.asof,../reference/api/pandas.Index.asof generated/pandas.Index.asof_locs,../reference/api/pandas.Index.asof_locs generated/pandas.Index.astype,../reference/api/pandas.Index.astype -generated/pandas.Index.contains,../reference/api/pandas.Index.contains generated/pandas.Index.copy,../reference/api/pandas.Index.copy generated/pandas.Index.data,../reference/api/pandas.Index.data generated/pandas.Index.delete,../reference/api/pandas.Index.delete diff --git a/doc/source/reference/indexing.rst b/doc/source/reference/indexing.rst index a01f2bcd40612..ec485675771c4 100644 --- a/doc/source/reference/indexing.rst +++ b/doc/source/reference/indexing.rst @@ -151,7 +151,6 @@ Selecting Index.asof Index.asof_locs - Index.contains Index.get_indexer Index.get_indexer_for Index.get_indexer_non_unique