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 diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 120976d475ac5..1ea33d2279c4e 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -548,6 +548,7 @@ 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`) - Passing ``int64`` values to :class:`DatetimeIndex` and a timezone now interprets the values as nanosecond timestamps in UTC, not wall times in the given timezone (:issue:`24559`) - 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`) - Addition and subtraction of ``int`` or integer-arrays is no longer allowed in :class:`Timestamp`, :class:`DatetimeIndex`, :class:`TimedeltaIndex`, use ``obj + n * obj.freq`` instead of ``obj + n`` (:issue:`22535`) - Removed :meth:`Series.from_array` (:issue:`18258`) - Removed :meth:`DataFrame.from_items` (: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 142533584670d..b730fd0f876fa 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1146,34 +1146,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/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 353210d7537c3..9cc1ab58c6de7 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -2402,11 +2402,13 @@ 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): + # GH#30103 method removed for all types except IntervalIndex + if isinstance(indices, pd.IntervalIndex): indices.contains(1) + else: + with pytest.raises(AttributeError): + indices.contains(1) class TestMixedIntIndex(Base): diff --git a/pandas/tests/indexes/test_range.py b/pandas/tests/indexes/test_range.py index b60d3126da1d5..13b8ca2a8ea22 100644 --- a/pandas/tests/indexes/test_range.py +++ b/pandas/tests/indexes/test_range.py @@ -306,14 +306,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