93
93
ensure_platform_int ,
94
94
is_any_real_numeric_dtype ,
95
95
is_bool_dtype ,
96
- is_categorical_dtype ,
97
96
is_dtype_equal ,
98
97
is_ea_or_datetimelike_dtype ,
99
98
is_extension_array_dtype ,
102
101
is_hashable ,
103
102
is_integer ,
104
103
is_integer_dtype ,
105
- is_interval_dtype ,
106
104
is_iterator ,
107
105
is_list_like ,
108
106
is_numeric_dtype ,
@@ -3746,7 +3744,7 @@ def get_indexer(
3746
3744
# matched to Interval scalars
3747
3745
return self ._get_indexer_non_comparable (target , method = method , unique = True )
3748
3746
3749
- if is_categorical_dtype (self .dtype ):
3747
+ if isinstance (self .dtype , CategoricalDtype ):
3750
3748
# _maybe_cast_listlike_indexer ensures target has our dtype
3751
3749
# (could improve perf by doing _should_compare check earlier?)
3752
3750
assert is_dtype_equal (self .dtype , target .dtype )
@@ -3764,7 +3762,7 @@ def get_indexer(
3764
3762
indexer [mask & ~ target_nans ] = - 1
3765
3763
return indexer
3766
3764
3767
- if is_categorical_dtype (target .dtype ):
3765
+ if isinstance (target .dtype , CategoricalDtype ):
3768
3766
# potential fastpath
3769
3767
# get an indexer for unique categories then propagate to codes via take_nd
3770
3768
# get_indexer instead of _get_indexer needed for MultiIndex cases
@@ -3842,8 +3840,8 @@ def _should_partial_index(self, target: Index) -> bool:
3842
3840
"""
3843
3841
Should we attempt partial-matching indexing?
3844
3842
"""
3845
- if is_interval_dtype (self .dtype ):
3846
- if is_interval_dtype (target .dtype ):
3843
+ if isinstance (self .dtype , IntervalDtype ):
3844
+ if isinstance (target .dtype , IntervalDtype ):
3847
3845
return False
3848
3846
# See https://github.com/pandas-dev/pandas/issues/47772 the commented
3849
3847
# out code can be restored (instead of hardcoding `return True`)
@@ -3880,7 +3878,7 @@ def _check_indexing_method(
3880
3878
"tolerance not implemented yet for MultiIndex"
3881
3879
)
3882
3880
3883
- if is_interval_dtype (self .dtype ) or is_categorical_dtype ( self . dtype ):
3881
+ if isinstance (self .dtype , ( IntervalDtype , CategoricalDtype ) ):
3884
3882
# GH#37871 for now this is only for IntervalIndex and CategoricalIndex
3885
3883
if method is not None :
3886
3884
raise NotImplementedError (
@@ -4082,7 +4080,7 @@ def _convert_slice_indexer(self, key: slice, kind: str_t):
4082
4080
4083
4081
# TODO(GH#50617): once Series.__[gs]etitem__ is removed we should be able
4084
4082
# to simplify this.
4085
- if isinstance (self .dtype , np .dtype ) and is_float_dtype ( self .dtype ) :
4083
+ if isinstance (self .dtype , np .dtype ) and self .dtype . kind == "f" :
4086
4084
# We always treat __getitem__ slicing as label-based
4087
4085
# translate to locations
4088
4086
return self .slice_indexer (start , stop , step )
@@ -4096,14 +4094,14 @@ def is_int(v):
4096
4094
# special case for interval_dtype bc we do not do partial-indexing
4097
4095
# on integer Intervals when slicing
4098
4096
# TODO: write this in terms of e.g. should_partial_index?
4099
- ints_are_positional = self ._should_fallback_to_positional or is_interval_dtype (
4100
- self .dtype
4097
+ ints_are_positional = self ._should_fallback_to_positional or isinstance (
4098
+ self .dtype , IntervalDtype
4101
4099
)
4102
4100
is_positional = is_index_slice and ints_are_positional
4103
4101
4104
4102
if kind == "getitem" :
4105
4103
# called from the getitem slicers, validate that we are in fact integers
4106
- if is_integer_dtype (self .dtype ) or is_index_slice :
4104
+ if is_index_slice or is_integer_dtype (self .dtype ):
4107
4105
# Note: these checks are redundant if we know is_index_slice
4108
4106
self ._validate_indexer ("slice" , key .start , "getitem" )
4109
4107
self ._validate_indexer ("slice" , key .stop , "getitem" )
@@ -4507,7 +4505,7 @@ def join(
4507
4505
return self ._join_non_unique (other , how = how )
4508
4506
elif not self .is_unique or not other .is_unique :
4509
4507
if self .is_monotonic_increasing and other .is_monotonic_increasing :
4510
- if not is_interval_dtype (self .dtype ):
4508
+ if not isinstance (self .dtype , IntervalDtype ):
4511
4509
# otherwise we will fall through to _join_via_get_indexer
4512
4510
# GH#39133
4513
4511
# go through object dtype for ea till engine is supported properly
@@ -4520,7 +4518,7 @@ def join(
4520
4518
and other .is_monotonic_increasing
4521
4519
and self ._can_use_libjoin
4522
4520
and not isinstance (self , ABCMultiIndex )
4523
- and not is_categorical_dtype (self .dtype )
4521
+ and not isinstance (self .dtype , CategoricalDtype )
4524
4522
):
4525
4523
# Categorical is monotonic if data are ordered as categories, but join can
4526
4524
# not handle this in case of not lexicographically monotonic GH#38502
@@ -4904,7 +4902,7 @@ def _can_use_libjoin(self) -> bool:
4904
4902
or isinstance (self .values , BaseMaskedArray )
4905
4903
or isinstance (self ._values , ArrowExtensionArray )
4906
4904
)
4907
- return not is_interval_dtype (self .dtype )
4905
+ return not isinstance (self .dtype , IntervalDtype )
4908
4906
4909
4907
# --------------------------------------------------------------------
4910
4908
# Uncategorized Methods
@@ -5230,7 +5228,7 @@ def _can_hold_identifiers_and_holds_name(self, name) -> bool:
5230
5228
if (
5231
5229
is_object_dtype (self .dtype )
5232
5230
or is_string_dtype (self .dtype )
5233
- or is_categorical_dtype (self .dtype )
5231
+ or isinstance (self .dtype , CategoricalDtype )
5234
5232
):
5235
5233
return name in self
5236
5234
return False
@@ -5930,11 +5928,11 @@ def _raise_if_missing(self, key, indexer, axis_name: str_t) -> None:
5930
5928
if nmissing :
5931
5929
# TODO: remove special-case; this is just to keep exception
5932
5930
# message tests from raising while debugging
5933
- use_interval_msg = is_interval_dtype (self .dtype ) or (
5934
- is_categorical_dtype (self .dtype )
5931
+ use_interval_msg = isinstance (self .dtype , IntervalDtype ) or (
5932
+ isinstance (self .dtype , CategoricalDtype )
5935
5933
# "Index" has no attribute "categories" [attr-defined]
5936
- and is_interval_dtype (
5937
- self .categories .dtype # type: ignore[attr-defined]
5934
+ and isinstance (
5935
+ self .categories .dtype , IntervalDtype # type: ignore[attr-defined]
5938
5936
)
5939
5937
)
5940
5938
@@ -6942,8 +6940,7 @@ def _maybe_disable_logical_methods(self, opname: str_t) -> None:
6942
6940
if (
6943
6941
isinstance (self , ABCMultiIndex )
6944
6942
or needs_i8_conversion (self .dtype )
6945
- or is_interval_dtype (self .dtype )
6946
- or is_categorical_dtype (self .dtype )
6943
+ or isinstance (self .dtype , (IntervalDtype , CategoricalDtype ))
6947
6944
or is_float_dtype (self .dtype )
6948
6945
):
6949
6946
# This call will raise
0 commit comments