Skip to content

Commit 576ea74

Browse files
authored
gh-514 Added ExtensionDtype for is_*_dtype functions (#517)
* added ExtensionDtpe in is_*_dtype() methods * commented the error lines * added reference to Pandas issue in commented lines
1 parent 314442d commit 576ea74

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

pandas-stubs/core/dtypes/common.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Union
22

33
import pandas as pd
4+
from pandas.api.extensions import ExtensionDtype
45
from typing_extensions import TypeAlias
56

67
from pandas._typing import (
@@ -29,7 +30,7 @@ from pandas.core.dtypes.inference import (
2930
)
3031

3132
_ArrayOrDtype: TypeAlias = Union[
32-
ArrayLike, npt.DTypeLike, pd.Series, pd.DataFrame, pd.Index
33+
ArrayLike, npt.DTypeLike, pd.Series, pd.DataFrame, pd.Index, ExtensionDtype
3334
]
3435

3536
def is_object_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ...

tests/test_api_types.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def test_is_bool_dtype() -> None:
4848
bool,
4949
)
5050
check(assert_type(api.is_bool_dtype(ind), bool), bool)
51+
check(assert_type(api.is_bool_dtype(ExtensionDtype), bool), bool)
5152

5253

5354
def test_is_categorical_dtype() -> None:
@@ -59,6 +60,7 @@ def test_is_categorical_dtype() -> None:
5960
bool,
6061
)
6162
check(assert_type(api.is_categorical_dtype(ind), bool), bool)
63+
check(assert_type(api.is_categorical_dtype(ExtensionDtype), bool), bool)
6264

6365

6466
def test_is_complex() -> None:
@@ -82,6 +84,7 @@ def test_is_complex_dtype() -> None:
8284
bool,
8385
)
8486
check(assert_type(api.is_complex_dtype(ind), bool), bool)
87+
# check(assert_type(api.is_complex_dtype(ExtensionDtype), bool), bool) pandas GH 50923
8588

8689

8790
def test_is_datetime64_any_dtype() -> None:
@@ -93,6 +96,7 @@ def test_is_datetime64_any_dtype() -> None:
9396
bool,
9497
)
9598
check(assert_type(api.is_datetime64_any_dtype(ind), bool), bool)
99+
# check(assert_type(api.is_datetime64_any_dtype(ExtensionDtype), bool), bool) pandas GH 50923
96100

97101

98102
def test_is_datetime64_dtype() -> None:
@@ -104,6 +108,7 @@ def test_is_datetime64_dtype() -> None:
104108
bool,
105109
)
106110
check(assert_type(api.is_datetime64_dtype(ind), bool), bool)
111+
# check(assert_type(api.is_datetime64_dtype(ExtensionDtype), bool), bool) pandas GH 50923
107112

108113

109114
def test_is_datetime64_ns_dtype() -> None:
@@ -115,6 +120,7 @@ def test_is_datetime64_ns_dtype() -> None:
115120
bool,
116121
)
117122
check(assert_type(api.is_datetime64_ns_dtype(ind), bool), bool)
123+
check(assert_type(api.is_datetime64_ns_dtype(ExtensionDtype), bool), bool)
118124

119125

120126
def test_is_datetime64tz_dtype() -> None:
@@ -126,6 +132,7 @@ def test_is_datetime64tz_dtype() -> None:
126132
bool,
127133
)
128134
check(assert_type(api.is_datetime64tz_dtype(ind), bool), bool)
135+
check(assert_type(api.is_datetime64tz_dtype(ExtensionDtype), bool), bool)
129136

130137

131138
def test_is_dict_like() -> None:
@@ -153,6 +160,7 @@ def test_is_extension_array_dtype() -> None:
153160
bool,
154161
)
155162
check(assert_type(api.is_extension_array_dtype(ind), bool), bool)
163+
check(assert_type(api.is_extension_array_dtype(ExtensionDtype), bool), bool)
156164

157165

158166
def test_is_file_like() -> None:
@@ -185,6 +193,7 @@ def test_is_float_dtype() -> None:
185193
bool,
186194
)
187195
check(assert_type(api.is_float_dtype(ind), bool), bool)
196+
# check(assert_type(api.is_float_dtype(ExtensionDtype), bool), bool) pandas GH 50923
188197

189198

190199
def test_is_hashable() -> None:
@@ -208,6 +217,7 @@ def test_is_int64_dtype() -> None:
208217
bool,
209218
)
210219
check(assert_type(api.is_int64_dtype(ind), bool), bool)
220+
# check(assert_type(api.is_int64_dtype(ExtensionDtype), bool), bool) pandas GH 50923
211221

212222

213223
def test_is_integer() -> None:
@@ -231,6 +241,7 @@ def test_is_integer_dtype() -> None:
231241
bool,
232242
)
233243
check(assert_type(api.is_integer_dtype(ind), bool), bool)
244+
# check(assert_type(api.is_integer_dtype(ExtensionDtype), bool), bool) pandas GH 50923
234245

235246

236247
def test_is_interval() -> None:
@@ -247,14 +258,15 @@ def test_is_interval() -> None:
247258

248259
def test_is_interval_dtype() -> None:
249260
check(assert_type(api.is_interval_dtype(obj), bool), bool)
250-
check(assert_type(api.is_interval(nparr), bool), bool)
251-
check(assert_type(api.is_interval(dtylike), bool), bool)
252-
check(assert_type(api.is_interval(arr), bool), bool)
261+
check(assert_type(api.is_interval_dtype(nparr), bool), bool)
262+
check(assert_type(api.is_interval_dtype(dtylike), bool), bool)
263+
check(assert_type(api.is_interval_dtype(arr), bool), bool)
253264
check(
254-
assert_type(api.is_interval(dframe), bool),
265+
assert_type(api.is_interval_dtype(dframe), bool),
255266
bool,
256267
)
257-
check(assert_type(api.is_interval(ind), bool), bool)
268+
check(assert_type(api.is_interval_dtype(ind), bool), bool)
269+
check(assert_type(api.is_interval_dtype(ExtensionDtype), bool), bool)
258270

259271

260272
def test_is_iterator() -> None:
@@ -311,6 +323,7 @@ def test_is_numeric_dtype() -> None:
311323
bool,
312324
)
313325
check(assert_type(api.is_numeric_dtype(ind), bool), bool)
326+
# check(assert_type(api.is_numeric_dtype(ExtensionDtype), bool), bool) pandas GH 50923
314327

315328

316329
def test_is_object_dtype() -> None:
@@ -322,6 +335,7 @@ def test_is_object_dtype() -> None:
322335
bool,
323336
)
324337
check(assert_type(api.is_object_dtype(ind), bool), bool)
338+
# check(assert_type(api.is_object_dtype(ExtensionDtype), bool), bool) pandas GH 50923
325339

326340

327341
def test_is_period_dtype() -> None:
@@ -333,6 +347,7 @@ def test_is_period_dtype() -> None:
333347
bool,
334348
)
335349
check(assert_type(api.is_period_dtype(ind), bool), bool)
350+
check(assert_type(api.is_period_dtype(ExtensionDtype), bool), bool)
336351

337352

338353
def test_is_re() -> None:
@@ -374,6 +389,7 @@ def test_is_signed_integer_dtype() -> None:
374389
bool,
375390
)
376391
check(assert_type(api.is_signed_integer_dtype(ind), bool), bool)
392+
# check(assert_type(api.is_signed_integer_dtype(ExtensionDtype), bool), bool) pandas GH 50923
377393

378394

379395
def test_is_sparse() -> None:
@@ -391,6 +407,7 @@ def test_is_string_dtype() -> None:
391407
bool,
392408
)
393409
check(assert_type(api.is_string_dtype(ind), bool), bool)
410+
check(assert_type(api.is_string_dtype(ExtensionDtype), bool), bool)
394411

395412

396413
def test_is_timedelta64_dtype() -> None:
@@ -402,6 +419,7 @@ def test_is_timedelta64_dtype() -> None:
402419
bool,
403420
)
404421
check(assert_type(api.is_timedelta64_dtype(ind), bool), bool)
422+
# check(assert_type(api.is_timedelta64_dtype(ExtensionDtype), bool), bool) pandas GH 50923
405423

406424

407425
def test_is_timedelta64_ns_dtype() -> None:
@@ -413,6 +431,7 @@ def test_is_timedelta64_ns_dtype() -> None:
413431
bool,
414432
)
415433
check(assert_type(api.is_timedelta64_ns_dtype(ind), bool), bool)
434+
check(assert_type(api.is_timedelta64_ns_dtype(ExtensionDtype), bool), bool)
416435

417436

418437
def test_is_unsigned_integer_dtype() -> None:
@@ -427,6 +446,7 @@ def test_is_unsigned_integer_dtype() -> None:
427446
bool,
428447
)
429448
check(assert_type(api.is_unsigned_integer_dtype(ind), bool), bool)
449+
# check(assert_type(api.is_unsigned_integer_dtype(ExtensionDtype), bool), bool) pandas GH 50923
430450

431451

432452
def test_pandas_dtype() -> None:

0 commit comments

Comments
 (0)