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: Index.contains, DatetimeIndex.offset #30103

Merged
merged 8 commits into from
Dec 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion doc/redirects.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion doc/source/reference/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ Selecting

Index.asof
Index.asof_locs
Index.contains
Index.get_indexer
Index.get_indexer_for
Index.get_indexer_non_unique
Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
20 changes: 0 additions & 20 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)}")

Expand Down
28 changes: 0 additions & 28 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 0 additions & 12 deletions pandas/tests/indexes/datetimes/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 6 additions & 4 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 0 additions & 8 deletions pandas/tests/indexes/test_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down