@@ -207,6 +207,12 @@ def is_sparse(arr) -> bool:
207
207
208
208
Returns `False` if the parameter has more than one dimension.
209
209
"""
210
+ warnings .warn (
211
+ "is_sparse is deprecated and will be removed in a future "
212
+ "version. Check `isinstance(dtype, pd.SparseDtype)` instead." ,
213
+ FutureWarning ,
214
+ stacklevel = find_stack_level (),
215
+ )
210
216
from pandas .core .arrays .sparse import SparseDtype
211
217
212
218
dtype = getattr (arr , "dtype" , arr )
@@ -399,6 +405,12 @@ def is_period_dtype(arr_or_dtype) -> bool:
399
405
>>> is_period_dtype(pd.PeriodIndex([], freq="A"))
400
406
True
401
407
"""
408
+ warnings .warn (
409
+ "is_period_dtype is deprecated and will be removed in a future version. "
410
+ "Use `isinstance(dtype, pd.PeriodDtype)` instead" ,
411
+ FutureWarning ,
412
+ stacklevel = find_stack_level (),
413
+ )
402
414
if isinstance (arr_or_dtype , ExtensionDtype ):
403
415
# GH#33400 fastpath for dtype object
404
416
return arr_or_dtype .type is Period
@@ -539,7 +551,7 @@ def is_string_dtype(arr_or_dtype) -> bool:
539
551
>>> is_string_dtype(pd.Series([1, 2], dtype=object))
540
552
False
541
553
"""
542
- if hasattr (arr_or_dtype , "dtype" ) and get_dtype (arr_or_dtype ).kind == "O" :
554
+ if hasattr (arr_or_dtype , "dtype" ) and _get_dtype (arr_or_dtype ).kind == "O" :
543
555
return is_all_strings (arr_or_dtype )
544
556
545
557
def condition (dtype ) -> bool :
@@ -585,7 +597,7 @@ def is_dtype_equal(source, target) -> bool:
585
597
# GH#38516 ensure we get the same behavior from
586
598
# is_dtype_equal(CDT, "category") and CDT == "category"
587
599
try :
588
- src = get_dtype (source )
600
+ src = _get_dtype (source )
589
601
if isinstance (src , ExtensionDtype ):
590
602
return src == target
591
603
except (TypeError , AttributeError , ImportError ):
@@ -594,8 +606,8 @@ def is_dtype_equal(source, target) -> bool:
594
606
return is_dtype_equal (target , source )
595
607
596
608
try :
597
- source = get_dtype (source )
598
- target = get_dtype (target )
609
+ source = _get_dtype (source )
610
+ target = _get_dtype (target )
599
611
return source == target
600
612
except (TypeError , AttributeError , ImportError ):
601
613
# invalid comparison
@@ -875,7 +887,7 @@ def is_datetime64_any_dtype(arr_or_dtype) -> bool:
875
887
return False
876
888
877
889
try :
878
- tipo = get_dtype (arr_or_dtype )
890
+ tipo = _get_dtype (arr_or_dtype )
879
891
except TypeError :
880
892
return False
881
893
return (isinstance (tipo , np .dtype ) and tipo .kind == "M" ) or isinstance (
@@ -923,7 +935,7 @@ def is_datetime64_ns_dtype(arr_or_dtype) -> bool:
923
935
if arr_or_dtype is None :
924
936
return False
925
937
try :
926
- tipo = get_dtype (arr_or_dtype )
938
+ tipo = _get_dtype (arr_or_dtype )
927
939
except TypeError :
928
940
return False
929
941
return tipo == DT64NS_DTYPE or (
@@ -1214,7 +1226,7 @@ def is_bool_dtype(arr_or_dtype) -> bool:
1214
1226
if arr_or_dtype is None :
1215
1227
return False
1216
1228
try :
1217
- dtype = get_dtype (arr_or_dtype )
1229
+ dtype = _get_dtype (arr_or_dtype )
1218
1230
except (TypeError , ValueError ):
1219
1231
return False
1220
1232
@@ -1373,13 +1385,13 @@ def _is_dtype(arr_or_dtype, condition) -> bool:
1373
1385
if arr_or_dtype is None :
1374
1386
return False
1375
1387
try :
1376
- dtype = get_dtype (arr_or_dtype )
1388
+ dtype = _get_dtype (arr_or_dtype )
1377
1389
except (TypeError , ValueError ):
1378
1390
return False
1379
1391
return condition (dtype )
1380
1392
1381
1393
1382
- def get_dtype (arr_or_dtype ) -> DtypeObj :
1394
+ def _get_dtype (arr_or_dtype ) -> DtypeObj :
1383
1395
"""
1384
1396
Get the dtype instance associated with an array
1385
1397
or dtype object.
@@ -1510,7 +1522,7 @@ def infer_dtype_from_object(dtype) -> type:
1510
1522
try :
1511
1523
return infer_dtype_from_object (getattr (np , dtype ))
1512
1524
except (AttributeError , TypeError ):
1513
- # Handles cases like get_dtype (int) i.e.,
1525
+ # Handles cases like _get_dtype (int) i.e.,
1514
1526
# Python objects that are valid dtypes
1515
1527
# (unlike user-defined types, in general)
1516
1528
#
@@ -1653,7 +1665,6 @@ def is_all_strings(value: ArrayLike) -> bool:
1653
1665
"ensure_float64" ,
1654
1666
"ensure_python_int" ,
1655
1667
"ensure_str" ,
1656
- "get_dtype" ,
1657
1668
"infer_dtype_from_object" ,
1658
1669
"INT64_DTYPE" ,
1659
1670
"is_1d_only_ea_dtype" ,
0 commit comments