Skip to content

Commit d5645c2

Browse files
Terji PetersenTerji Petersen
Terji Petersen
authored and
Terji Petersen
committed
DEPR: deprecate Index.is_integer
1 parent 5fad2e4 commit d5645c2

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

doc/source/whatsnew/v2.0.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ Other API changes
416416

417417
Deprecations
418418
~~~~~~~~~~~~
419-
-
419+
- :meth:`Index.is_integer` has been deprecated. Use :func:`pandas.api.types.is_integer_dtype` instead (:issue:`50042`)
420420

421421
.. ---------------------------------------------------------------------------
422422

pandas/_testing/asserters.py

Lines changed: 2 additions & 1 deletion
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,
@@ -1322,7 +1323,7 @@ def assert_indexing_slices_equivalent(ser: Series, l_slc: slice, i_slc: slice) -
13221323

13231324
assert_series_equal(ser.loc[l_slc], expected)
13241325

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

pandas/core/indexes/base.py

Lines changed: 18 additions & 8 deletions
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,
@@ -2200,7 +2201,7 @@ def is_boolean(self) -> bool:
22002201
22012202
See Also
22022203
--------
2203-
is_integer : Check if the Index only consists of integers.
2204+
is_integer : Check if the Index only consists of integers (deprecated).
22042205
is_floating : Check if the Index is a floating type.
22052206
is_numeric : Check if the Index only consists of numeric data.
22062207
is_object : Check if the Index is of the object dtype.
@@ -2228,6 +2229,9 @@ def is_integer(self) -> bool:
22282229
"""
22292230
Check if the Index only consists of integers.
22302231
2232+
.. deprecated:: 2.0.0
2233+
Use `pandas.api.types.is_integer_dtype` instead.
2234+
22312235
Returns
22322236
-------
22332237
bool
@@ -2256,6 +2260,12 @@ def is_integer(self) -> bool:
22562260
>>> idx.is_integer()
22572261
False
22582262
"""
2263+
warnings.warn(
2264+
f"{type(self).__name__}.is_integer is deprecated."
2265+
"Use pandas.api.types.is_integer_dtype instead",
2266+
FutureWarning,
2267+
stacklevel=find_stack_level(),
2268+
)
22592269
return self.inferred_type in ["integer"]
22602270

22612271
@final
@@ -2275,7 +2285,7 @@ def is_floating(self) -> bool:
22752285
See Also
22762286
--------
22772287
is_boolean : Check if the Index only consists of booleans.
2278-
is_integer : Check if the Index only consists of integers.
2288+
is_integer : Check if the Index only consists of integers (deprecated).
22792289
is_numeric : Check if the Index only consists of numeric data.
22802290
is_object : Check if the Index is of the object dtype.
22812291
is_categorical : Check if the Index holds categorical data.
@@ -2314,7 +2324,7 @@ def is_numeric(self) -> bool:
23142324
See Also
23152325
--------
23162326
is_boolean : Check if the Index only consists of booleans.
2317-
is_integer : Check if the Index only consists of integers.
2327+
is_integer : Check if the Index only consists of integers (deprecated).
23182328
is_floating : Check if the Index is a floating type.
23192329
is_object : Check if the Index is of the object dtype.
23202330
is_categorical : Check if the Index holds categorical data.
@@ -2357,7 +2367,7 @@ def is_object(self) -> bool:
23572367
See Also
23582368
--------
23592369
is_boolean : Check if the Index only consists of booleans.
2360-
is_integer : Check if the Index only consists of integers.
2370+
is_integer : Check if the Index only consists of integers (deprecated).
23612371
is_floating : Check if the Index is a floating type.
23622372
is_numeric : Check if the Index only consists of numeric data.
23632373
is_categorical : Check if the Index holds categorical data.
@@ -2398,7 +2408,7 @@ def is_categorical(self) -> bool:
23982408
--------
23992409
CategoricalIndex : Index for categorical data.
24002410
is_boolean : Check if the Index only consists of booleans.
2401-
is_integer : Check if the Index only consists of integers.
2411+
is_integer : Check if the Index only consists of integers (deprecated).
24022412
is_floating : Check if the Index is a floating type.
24032413
is_numeric : Check if the Index only consists of numeric data.
24042414
is_object : Check if the Index is of the object dtype.
@@ -2441,7 +2451,7 @@ def is_interval(self) -> bool:
24412451
--------
24422452
IntervalIndex : Index for Interval objects.
24432453
is_boolean : Check if the Index only consists of booleans.
2444-
is_integer : Check if the Index only consists of integers.
2454+
is_integer : Check if the Index only consists of integers (deprecated).
24452455
is_floating : Check if the Index is a floating type.
24462456
is_numeric : Check if the Index only consists of numeric data.
24472457
is_object : Check if the Index is of the object dtype.
@@ -3883,7 +3893,7 @@ def is_int(v):
38833893

38843894
if kind == "getitem":
38853895
# called from the getitem slicers, validate that we are in fact integers
3886-
if self.is_integer():
3896+
if is_integer_dtype(self.dtype):
38873897
if is_frame:
38883898
# unambiguously positional, no deprecation
38893899
pass
@@ -3919,7 +3929,7 @@ def is_int(v):
39193929
FutureWarning,
39203930
stacklevel=find_stack_level(),
39213931
)
3922-
if self.is_integer() or is_index_slice:
3932+
if is_integer_dtype(self.dtype) or is_index_slice:
39233933
# Note: these checks are redundant if we know is_index_slice
39243934
self._validate_indexer("slice", key.start, "getitem")
39253935
self._validate_indexer("slice", key.stop, "getitem")

pandas/tests/indexes/common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,12 @@ def test_inv(self, simple_index):
795795
with pytest.raises(TypeError, match=msg):
796796
~Series(idx)
797797

798+
def test_is_integer_is_deprecated(self, simple_index):
799+
# GH50042
800+
idx = simple_index
801+
with tm.assert_produces_warning(FutureWarning):
802+
idx.is_integer()
803+
798804

799805
class NumericBase(Base):
800806
"""

pandas/tests/indexing/test_indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ def test_index_type_coercion(self, indexer):
601601
# integer indexes
602602
for s in [Series(range(5)), Series(range(5), index=range(1, 6))]:
603603

604-
assert s.index.is_integer()
604+
assert is_integer_dtype(s.index)
605605

606606
s2 = s.copy()
607607
indexer(s2)[0.1] = 0

0 commit comments

Comments
 (0)