Skip to content

Commit 5d96fad

Browse files
jbrockmendelproost
authored andcommitted
DEPR: Index.contains, DatetimeIndex.offset (pandas-dev#30103)
1 parent bc4c5ef commit 5d96fad

File tree

8 files changed

+7
-74
lines changed

8 files changed

+7
-74
lines changed

doc/redirects.csv

-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,6 @@ generated/pandas.Index.asi8,../reference/api/pandas.Index.asi8
618618
generated/pandas.Index.asof,../reference/api/pandas.Index.asof
619619
generated/pandas.Index.asof_locs,../reference/api/pandas.Index.asof_locs
620620
generated/pandas.Index.astype,../reference/api/pandas.Index.astype
621-
generated/pandas.Index.contains,../reference/api/pandas.Index.contains
622621
generated/pandas.Index.copy,../reference/api/pandas.Index.copy
623622
generated/pandas.Index.data,../reference/api/pandas.Index.data
624623
generated/pandas.Index.delete,../reference/api/pandas.Index.delete

doc/source/reference/indexing.rst

-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ Selecting
151151

152152
Index.asof
153153
Index.asof_locs
154-
Index.contains
155154
Index.get_indexer
156155
Index.get_indexer_for
157156
Index.get_indexer_non_unique

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
549549
- Passing ``datetime64`` data to :class:`TimedeltaIndex` or ``timedelta64`` data to ``DatetimeIndex`` now raises ``TypeError`` (:issue:`23539`, :issue:`23937`)
550550
- 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`)
551551
- A tuple passed to :meth:`DataFrame.groupby` is now exclusively treated as a single key (:issue:`18314`)
552+
- Removed the previously deprecated :meth:`Index.contains`, use ``key in index`` instead (:issue:`30103`)
552553
- 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`)
553554
- Removed :meth:`Series.from_array` (:issue:`18258`)
554555
- Removed :meth:`DataFrame.from_items` (:issue:`18458`)

pandas/core/indexes/base.py

-20
Original file line numberDiff line numberDiff line change
@@ -3994,26 +3994,6 @@ def __contains__(self, key) -> bool:
39943994
except (OverflowError, TypeError, ValueError):
39953995
return False
39963996

3997-
def contains(self, key) -> bool:
3998-
"""
3999-
Return a boolean indicating whether the provided key is in the index.
4000-
4001-
.. deprecated:: 0.25.0
4002-
Use ``key in index`` instead of ``index.contains(key)``.
4003-
4004-
Returns
4005-
-------
4006-
bool
4007-
"""
4008-
warnings.warn(
4009-
"The 'contains' method is deprecated and will be removed in a "
4010-
"future version. Use 'key in index' instead of "
4011-
"'index.contains(key)'",
4012-
FutureWarning,
4013-
stacklevel=2,
4014-
)
4015-
return key in self
4016-
40173997
def __hash__(self):
40183998
raise TypeError(f"unhashable type: {repr(type(self).__name__)}")
40193999

pandas/core/indexes/datetimes.py

-28
Original file line numberDiff line numberDiff line change
@@ -1146,34 +1146,6 @@ def slice_indexer(self, start=None, end=None, step=None, kind=None):
11461146

11471147
_has_same_tz = ea_passthrough(DatetimeArray._has_same_tz)
11481148

1149-
@property
1150-
def offset(self):
1151-
"""
1152-
get/set the frequency of the instance
1153-
"""
1154-
msg = (
1155-
"{cls}.offset has been deprecated and will be removed "
1156-
"in a future version; use {cls}.freq instead.".format(
1157-
cls=type(self).__name__
1158-
)
1159-
)
1160-
warnings.warn(msg, FutureWarning, stacklevel=2)
1161-
return self.freq
1162-
1163-
@offset.setter
1164-
def offset(self, value):
1165-
"""
1166-
get/set the frequency of the instance
1167-
"""
1168-
msg = (
1169-
"{cls}.offset has been deprecated and will be removed "
1170-
"in a future version; use {cls}.freq instead.".format(
1171-
cls=type(self).__name__
1172-
)
1173-
)
1174-
warnings.warn(msg, FutureWarning, stacklevel=2)
1175-
self._data.freq = value
1176-
11771149
def __getitem__(self, key):
11781150
result = self._data.__getitem__(key)
11791151
if is_scalar(result):

pandas/tests/indexes/datetimes/test_ops.py

-12
Original file line numberDiff line numberDiff line change
@@ -437,18 +437,6 @@ def test_freq_setter_errors(self):
437437
with pytest.raises(ValueError, match="Invalid frequency"):
438438
idx._data.freq = "foo"
439439

440-
def test_offset_deprecated(self):
441-
# GH 20716
442-
idx = pd.DatetimeIndex(["20180101", "20180102"])
443-
444-
# getter deprecated
445-
with tm.assert_produces_warning(FutureWarning):
446-
idx.offset
447-
448-
# setter deprecated
449-
with tm.assert_produces_warning(FutureWarning):
450-
idx.offset = BDay()
451-
452440

453441
class TestBusinessDatetimeIndex:
454442
def setup_method(self, method):

pandas/tests/indexes/test_base.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -2426,11 +2426,13 @@ def test_tab_complete_warning(self, ip):
24262426
with provisionalcompleter("ignore"):
24272427
list(ip.Completer.completions("idx.", 4))
24282428

2429-
def test_deprecated_contains(self, indices):
2430-
# deprecated for all types except IntervalIndex
2431-
warning = FutureWarning if not isinstance(indices, pd.IntervalIndex) else None
2432-
with tm.assert_produces_warning(warning):
2429+
def test_contains_method_removed(self, indices):
2430+
# GH#30103 method removed for all types except IntervalIndex
2431+
if isinstance(indices, pd.IntervalIndex):
24332432
indices.contains(1)
2433+
else:
2434+
with pytest.raises(AttributeError):
2435+
indices.contains(1)
24342436

24352437

24362438
class TestMixedIntIndex(Base):

pandas/tests/indexes/test_range.py

-8
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,6 @@ def test_cached_data(self):
306306
91 in idx
307307
assert idx._cached_data is None
308308

309-
with tm.assert_produces_warning(FutureWarning):
310-
idx.contains(90)
311-
assert idx._cached_data is None
312-
313-
with tm.assert_produces_warning(FutureWarning):
314-
idx.contains(91)
315-
assert idx._cached_data is None
316-
317309
idx.all()
318310
assert idx._cached_data is None
319311

0 commit comments

Comments
 (0)