Skip to content

Commit 627bc40

Browse files
authored
DEPR: deprecate Index.is_integer (#50178)
1 parent b00148b commit 627bc40

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

doc/source/whatsnew/v2.0.0.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,7 @@ Deprecations
569569
~~~~~~~~~~~~
570570
- 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`)
571571
- Deprecated :func:`pandas.io.sql.execute`(:issue:`50185`)
572-
-
573-
572+
- :meth:`Index.is_integer` has been deprecated. Use :func:`pandas.api.types.is_integer_dtype` instead (:issue:`50042`)
574573
- :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`)
575574

576575
.. ---------------------------------------------------------------------------

pandas/_testing/asserters.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
is_bool,
1616
is_categorical_dtype,
1717
is_extension_array_dtype,
18+
is_integer_dtype,
1819
is_interval_dtype,
1920
is_number,
2021
is_numeric_dtype,
@@ -1335,7 +1336,7 @@ def assert_indexing_slices_equivalent(ser: Series, l_slc: slice, i_slc: slice) -
13351336

13361337
assert_series_equal(ser.loc[l_slc], expected)
13371338

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

pandas/core/indexes/base.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
is_float_dtype,
9999
is_hashable,
100100
is_integer,
101+
is_integer_dtype,
101102
is_interval_dtype,
102103
is_iterator,
103104
is_list_like,
@@ -2188,7 +2189,7 @@ def is_boolean(self) -> bool:
21882189
21892190
See Also
21902191
--------
2191-
is_integer : Check if the Index only consists of integers.
2192+
is_integer : Check if the Index only consists of integers (deprecated).
21922193
is_floating : Check if the Index is a floating type (deprecated).
21932194
is_numeric : Check if the Index only consists of numeric data.
21942195
is_object : Check if the Index is of the object dtype.
@@ -2216,6 +2217,9 @@ def is_integer(self) -> bool:
22162217
"""
22172218
Check if the Index only consists of integers.
22182219
2220+
.. deprecated:: 2.0.0
2221+
Use `pandas.api.types.is_integer_dtype` instead.
2222+
22192223
Returns
22202224
-------
22212225
bool
@@ -2244,6 +2248,12 @@ def is_integer(self) -> bool:
22442248
>>> idx.is_integer()
22452249
False
22462250
"""
2251+
warnings.warn(
2252+
f"{type(self).__name__}.is_integer is deprecated. "
2253+
"Use pandas.api.types.is_integer_dtype instead.",
2254+
FutureWarning,
2255+
stacklevel=find_stack_level(),
2256+
)
22472257
return self.inferred_type in ["integer"]
22482258

22492259
@final
@@ -2266,7 +2276,7 @@ def is_floating(self) -> bool:
22662276
See Also
22672277
--------
22682278
is_boolean : Check if the Index only consists of booleans.
2269-
is_integer : Check if the Index only consists of integers.
2279+
is_integer : Check if the Index only consists of integers (deprecated).
22702280
is_numeric : Check if the Index only consists of numeric data.
22712281
is_object : Check if the Index is of the object dtype.
22722282
is_categorical : Check if the Index holds categorical data.
@@ -2311,7 +2321,7 @@ def is_numeric(self) -> bool:
23112321
See Also
23122322
--------
23132323
is_boolean : Check if the Index only consists of booleans.
2314-
is_integer : Check if the Index only consists of integers.
2324+
is_integer : Check if the Index only consists of integers (deprecated).
23152325
is_floating : Check if the Index is a floating type (deprecated).
23162326
is_object : Check if the Index is of the object dtype.
23172327
is_categorical : Check if the Index holds categorical data.
@@ -2354,7 +2364,7 @@ def is_object(self) -> bool:
23542364
See Also
23552365
--------
23562366
is_boolean : Check if the Index only consists of booleans.
2357-
is_integer : Check if the Index only consists of integers.
2367+
is_integer : Check if the Index only consists of integers (deprecated).
23582368
is_floating : Check if the Index is a floating type (deprecated).
23592369
is_numeric : Check if the Index only consists of numeric data.
23602370
is_categorical : Check if the Index holds categorical data.
@@ -2395,7 +2405,7 @@ def is_categorical(self) -> bool:
23952405
--------
23962406
CategoricalIndex : Index for categorical data.
23972407
is_boolean : Check if the Index only consists of booleans.
2398-
is_integer : Check if the Index only consists of integers.
2408+
is_integer : Check if the Index only consists of integers (deprecated).
23992409
is_floating : Check if the Index is a floating type (deprecated).
24002410
is_numeric : Check if the Index only consists of numeric data.
24012411
is_object : Check if the Index is of the object dtype.
@@ -2438,7 +2448,7 @@ def is_interval(self) -> bool:
24382448
--------
24392449
IntervalIndex : Index for Interval objects.
24402450
is_boolean : Check if the Index only consists of booleans.
2441-
is_integer : Check if the Index only consists of integers.
2451+
is_integer : Check if the Index only consists of integers (deprecated).
24422452
is_floating : Check if the Index is a floating type (deprecated).
24432453
is_numeric : Check if the Index only consists of numeric data.
24442454
is_object : Check if the Index is of the object dtype.
@@ -3877,7 +3887,7 @@ def is_int(v):
38773887

38783888
if kind == "getitem":
38793889
# called from the getitem slicers, validate that we are in fact integers
3880-
if self.is_integer() or is_index_slice:
3890+
if is_integer_dtype(self.dtype) or is_index_slice:
38813891
# Note: these checks are redundant if we know is_index_slice
38823892
self._validate_indexer("slice", key.start, "getitem")
38833893
self._validate_indexer("slice", key.stop, "getitem")

pandas/tests/indexes/common.py

+6
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,12 @@ def test_is_floating_is_deprecated(self, simple_index):
803803
with tm.assert_produces_warning(FutureWarning):
804804
idx.is_floating()
805805

806+
def test_is_integer_is_deprecated(self, simple_index):
807+
# GH50042
808+
idx = simple_index
809+
with tm.assert_produces_warning(FutureWarning):
810+
idx.is_integer()
811+
806812

807813
class NumericBase(Base):
808814
"""

pandas/tests/indexing/test_indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ def test_index_type_coercion(self, indexer):
603603
# integer indexes
604604
for s in [Series(range(5)), Series(range(5), index=range(1, 6))]:
605605

606-
assert s.index.is_integer()
606+
assert is_integer_dtype(s.index)
607607

608608
s2 = s.copy()
609609
indexer(s2)[0.1] = 0

0 commit comments

Comments
 (0)