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: deprecate Index.is_integer #50178

Merged
merged 2 commits into from
Jan 13, 2023
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
3 changes: 1 addition & 2 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,7 @@ Deprecations
~~~~~~~~~~~~
- Deprecated argument ``infer_datetime_format`` in :func:`to_datetime` and :func:`read_csv`, as a strict version of it is now the default (:issue:`48621`)
- Deprecated :func:`pandas.io.sql.execute`(:issue:`50185`)
-

- :meth:`Index.is_integer` has been deprecated. Use :func:`pandas.api.types.is_integer_dtype` instead (:issue:`50042`)
- :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`)

.. ---------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
is_bool,
is_categorical_dtype,
is_extension_array_dtype,
is_integer_dtype,
is_interval_dtype,
is_number,
is_numeric_dtype,
Expand Down Expand Up @@ -1335,7 +1336,7 @@ def assert_indexing_slices_equivalent(ser: Series, l_slc: slice, i_slc: slice) -

assert_series_equal(ser.loc[l_slc], expected)

if not ser.index.is_integer():
if not is_integer_dtype(ser.index):
# For integer indices, .loc and plain getitem are position-based.
assert_series_equal(ser[l_slc], expected)

Expand Down
24 changes: 17 additions & 7 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
is_float_dtype,
is_hashable,
is_integer,
is_integer_dtype,
is_interval_dtype,
is_iterator,
is_list_like,
Expand Down Expand Up @@ -2188,7 +2189,7 @@ def is_boolean(self) -> bool:

See Also
--------
is_integer : Check if the Index only consists of integers.
is_integer : Check if the Index only consists of integers (deprecated).
is_floating : Check if the Index is a floating type (deprecated).
is_numeric : Check if the Index only consists of numeric data.
is_object : Check if the Index is of the object dtype.
Expand Down Expand Up @@ -2216,6 +2217,9 @@ def is_integer(self) -> bool:
"""
Check if the Index only consists of integers.

.. deprecated:: 2.0.0
Use `pandas.api.types.is_integer_dtype` instead.

Returns
-------
bool
Expand Down Expand Up @@ -2244,6 +2248,12 @@ def is_integer(self) -> bool:
>>> idx.is_integer()
False
"""
warnings.warn(
f"{type(self).__name__}.is_integer is deprecated. "
"Use pandas.api.types.is_integer_dtype instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self.inferred_type in ["integer"]

@final
Expand All @@ -2266,7 +2276,7 @@ def is_floating(self) -> bool:
See Also
--------
is_boolean : Check if the Index only consists of booleans.
is_integer : Check if the Index only consists of integers.
is_integer : Check if the Index only consists of integers (deprecated).
is_numeric : Check if the Index only consists of numeric data.
is_object : Check if the Index is of the object dtype.
is_categorical : Check if the Index holds categorical data.
Expand Down Expand Up @@ -2311,7 +2321,7 @@ def is_numeric(self) -> bool:
See Also
--------
is_boolean : Check if the Index only consists of booleans.
is_integer : Check if the Index only consists of integers.
is_integer : Check if the Index only consists of integers (deprecated).
is_floating : Check if the Index is a floating type (deprecated).
is_object : Check if the Index is of the object dtype.
is_categorical : Check if the Index holds categorical data.
Expand Down Expand Up @@ -2354,7 +2364,7 @@ def is_object(self) -> bool:
See Also
--------
is_boolean : Check if the Index only consists of booleans.
is_integer : Check if the Index only consists of integers.
is_integer : Check if the Index only consists of integers (deprecated).
is_floating : Check if the Index is a floating type (deprecated).
is_numeric : Check if the Index only consists of numeric data.
is_categorical : Check if the Index holds categorical data.
Expand Down Expand Up @@ -2395,7 +2405,7 @@ def is_categorical(self) -> bool:
--------
CategoricalIndex : Index for categorical data.
is_boolean : Check if the Index only consists of booleans.
is_integer : Check if the Index only consists of integers.
is_integer : Check if the Index only consists of integers (deprecated).
is_floating : Check if the Index is a floating type (deprecated).
is_numeric : Check if the Index only consists of numeric data.
is_object : Check if the Index is of the object dtype.
Expand Down Expand Up @@ -2438,7 +2448,7 @@ def is_interval(self) -> bool:
--------
IntervalIndex : Index for Interval objects.
is_boolean : Check if the Index only consists of booleans.
is_integer : Check if the Index only consists of integers.
is_integer : Check if the Index only consists of integers (deprecated).
is_floating : Check if the Index is a floating type (deprecated).
is_numeric : Check if the Index only consists of numeric data.
is_object : Check if the Index is of the object dtype.
Expand Down Expand Up @@ -3877,7 +3887,7 @@ def is_int(v):

if kind == "getitem":
# called from the getitem slicers, validate that we are in fact integers
if self.is_integer() or is_index_slice:
if is_integer_dtype(self.dtype) or is_index_slice:
# Note: these checks are redundant if we know is_index_slice
self._validate_indexer("slice", key.start, "getitem")
self._validate_indexer("slice", key.stop, "getitem")
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,12 @@ def test_is_floating_is_deprecated(self, simple_index):
with tm.assert_produces_warning(FutureWarning):
idx.is_floating()

def test_is_integer_is_deprecated(self, simple_index):
# GH50042
idx = simple_index
with tm.assert_produces_warning(FutureWarning):
idx.is_integer()


class NumericBase(Base):
"""
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def test_index_type_coercion(self, indexer):
# integer indexes
for s in [Series(range(5)), Series(range(5), index=range(1, 6))]:

assert s.index.is_integer()
assert is_integer_dtype(s.index)

s2 = s.copy()
indexer(s2)[0.1] = 0
Expand Down