88
88
ensure_int64 ,
89
89
ensure_object ,
90
90
ensure_platform_int ,
91
+ is_any_numeric_dtype ,
91
92
is_bool_dtype ,
92
93
is_categorical_dtype ,
93
94
is_dtype_equal ,
@@ -2278,7 +2279,7 @@ def is_boolean(self) -> bool:
2278
2279
--------
2279
2280
is_integer : Check if the Index only consists of integers (deprecated).
2280
2281
is_floating : Check if the Index is a floating type (deprecated).
2281
- is_numeric : Check if the Index only consists of numeric data.
2282
+ is_numeric : Check if the Index only consists of numeric data (deprecated) .
2282
2283
is_object : Check if the Index is of the object dtype (deprecated).
2283
2284
is_categorical : Check if the Index holds categorical data.
2284
2285
is_interval : Check if the Index holds Interval objects (deprecated).
@@ -2322,7 +2323,7 @@ def is_integer(self) -> bool:
2322
2323
--------
2323
2324
is_boolean : Check if the Index only consists of booleans (deprecated).
2324
2325
is_floating : Check if the Index is a floating type (deprecated).
2325
- is_numeric : Check if the Index only consists of numeric data.
2326
+ is_numeric : Check if the Index only consists of numeric data (deprecated) .
2326
2327
is_object : Check if the Index is of the object dtype. (deprecated).
2327
2328
is_categorical : Check if the Index holds categorical data (deprecated).
2328
2329
is_interval : Check if the Index holds Interval objects (deprecated).
@@ -2370,7 +2371,7 @@ def is_floating(self) -> bool:
2370
2371
--------
2371
2372
is_boolean : Check if the Index only consists of booleans (deprecated).
2372
2373
is_integer : Check if the Index only consists of integers (deprecated).
2373
- is_numeric : Check if the Index only consists of numeric data.
2374
+ is_numeric : Check if the Index only consists of numeric data (deprecated) .
2374
2375
is_object : Check if the Index is of the object dtype. (deprecated).
2375
2376
is_categorical : Check if the Index holds categorical data (deprecated).
2376
2377
is_interval : Check if the Index holds Interval objects (deprecated).
@@ -2406,6 +2407,9 @@ def is_numeric(self) -> bool:
2406
2407
"""
2407
2408
Check if the Index only consists of numeric data.
2408
2409
2410
+ .. deprecated:: 2.0.0
2411
+ Use `pandas.api.types.is_numeric_dtype` instead.
2412
+
2409
2413
Returns
2410
2414
-------
2411
2415
bool
@@ -2442,6 +2446,12 @@ def is_numeric(self) -> bool:
2442
2446
>>> idx.is_numeric()
2443
2447
False
2444
2448
"""
2449
+ warnings .warn (
2450
+ f"{ type (self ).__name__ } .is_numeric is deprecated. "
2451
+ "Use pandas.api.types.is_numeric_dtype instead" ,
2452
+ FutureWarning ,
2453
+ stacklevel = find_stack_level (),
2454
+ )
2445
2455
return self .inferred_type in ["integer" , "floating" ]
2446
2456
2447
2457
@final
@@ -2462,7 +2472,7 @@ def is_object(self) -> bool:
2462
2472
is_boolean : Check if the Index only consists of booleans (deprecated).
2463
2473
is_integer : Check if the Index only consists of integers (deprecated).
2464
2474
is_floating : Check if the Index is a floating type (deprecated).
2465
- is_numeric : Check if the Index only consists of numeric data.
2475
+ is_numeric : Check if the Index only consists of numeric data (deprecated) .
2466
2476
is_categorical : Check if the Index holds categorical data (deprecated).
2467
2477
is_interval : Check if the Index holds Interval objects (deprecated).
2468
2478
@@ -2512,7 +2522,7 @@ def is_categorical(self) -> bool:
2512
2522
is_boolean : Check if the Index only consists of booleans (deprecated).
2513
2523
is_integer : Check if the Index only consists of integers (deprecated).
2514
2524
is_floating : Check if the Index is a floating type (deprecated).
2515
- is_numeric : Check if the Index only consists of numeric data.
2525
+ is_numeric : Check if the Index only consists of numeric data (deprecated) .
2516
2526
is_object : Check if the Index is of the object dtype. (deprecated).
2517
2527
is_interval : Check if the Index holds Interval objects (deprecated).
2518
2528
@@ -2565,7 +2575,7 @@ def is_interval(self) -> bool:
2565
2575
is_boolean : Check if the Index only consists of booleans (deprecated).
2566
2576
is_integer : Check if the Index only consists of integers (deprecated).
2567
2577
is_floating : Check if the Index is a floating type (deprecated).
2568
- is_numeric : Check if the Index only consists of numeric data.
2578
+ is_numeric : Check if the Index only consists of numeric data (deprecated) .
2569
2579
is_object : Check if the Index is of the object dtype. (deprecated).
2570
2580
is_categorical : Check if the Index holds categorical data (deprecated).
2571
2581
@@ -3360,7 +3370,7 @@ def _intersection(self, other: Index, sort: bool = False):
3360
3370
pass
3361
3371
else :
3362
3372
# TODO: algos.unique1d should preserve DTA/TDA
3363
- if self . is_numeric ( ):
3373
+ if is_numeric_dtype ( self ):
3364
3374
# This is faster, because Index.unique() checks for uniqueness
3365
3375
# before calculating the unique values.
3366
3376
res = algos .unique1d (res_indexer )
@@ -6037,8 +6047,8 @@ def _should_compare(self, other: Index) -> bool:
6037
6047
Check if `self == other` can ever have non-False entries.
6038
6048
"""
6039
6049
6040
- if (is_bool_dtype (other ) and self . is_numeric ( )) or (
6041
- is_bool_dtype (self ) and other . is_numeric ( )
6050
+ if (is_bool_dtype (other ) and is_any_numeric_dtype ( self )) or (
6051
+ is_bool_dtype (self ) and is_any_numeric_dtype ( other )
6042
6052
):
6043
6053
# GH#16877 Treat boolean labels passed to a numeric index as not
6044
6054
# found. Without this fix False and True would be treated as 0 and 1
0 commit comments