Skip to content

Commit

Permalink
DEPR: deprecate Index.is_integer
Browse files Browse the repository at this point in the history
  • Loading branch information
Terji Petersen authored and Terji Petersen committed Dec 10, 2022
1 parent 5fad2e4 commit d5645c2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ Other API changes

Deprecations
~~~~~~~~~~~~
-
- :meth:`Index.is_integer` has been deprecated. Use :func:`pandas.api.types.is_integer_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 @@ -1322,7 +1323,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
26 changes: 18 additions & 8 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 @@ -2200,7 +2201,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.
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 @@ -2228,6 +2229,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 @@ -2256,6 +2260,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 @@ -2275,7 +2285,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 @@ -2314,7 +2324,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.
is_object : Check if the Index is of the object dtype.
is_categorical : Check if the Index holds categorical data.
Expand Down Expand Up @@ -2357,7 +2367,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.
is_numeric : Check if the Index only consists of numeric data.
is_categorical : Check if the Index holds categorical data.
Expand Down Expand Up @@ -2398,7 +2408,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.
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 @@ -2441,7 +2451,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.
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 @@ -3883,7 +3893,7 @@ def is_int(v):

if kind == "getitem":
# called from the getitem slicers, validate that we are in fact integers
if self.is_integer():
if is_integer_dtype(self.dtype):
if is_frame:
# unambiguously positional, no deprecation
pass
Expand Down Expand Up @@ -3919,7 +3929,7 @@ def is_int(v):
FutureWarning,
stacklevel=find_stack_level(),
)
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 @@ -795,6 +795,12 @@ def test_inv(self, simple_index):
with pytest.raises(TypeError, match=msg):
~Series(idx)

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 @@ -601,7 +601,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

0 comments on commit d5645c2

Please sign in to comment.