8
8
import pandas .util ._test_decorators as td
9
9
10
10
from pandas .core .dtypes .astype import astype_nansafe
11
+ from pandas .core .dtypes .base import (
12
+ ExtensionDtype ,
13
+ _registry ,
14
+ )
11
15
import pandas .core .dtypes .common as com
12
16
from pandas .core .dtypes .dtypes import (
13
17
CategoricalDtype ,
23
27
from pandas .api .types import pandas_dtype
24
28
from pandas .arrays import SparseArray
25
29
30
+ ALL_EA_DTYPES = _registry .dtypes
31
+
26
32
27
33
# EA & Actual Dtypes
28
34
def to_ea_dtypes (dtypes ):
@@ -36,25 +42,36 @@ def to_numpy_dtypes(dtypes):
36
42
37
43
38
44
class TestPandasDtype :
39
-
40
45
# Passing invalid dtype, both as a string or object, must raise TypeError
41
46
# Per issue GH15520
42
47
@pytest .mark .parametrize ("box" , [pd .Timestamp , "pd.Timestamp" , list ])
43
48
def test_invalid_dtype_error (self , box ):
44
- with pytest .raises (TypeError , match = "not understood" ):
49
+ msg = "|" .join (
50
+ (
51
+ "Must pass dtype instance, not dtype class" ,
52
+ "not understood" ,
53
+ )
54
+ )
55
+ with pytest .raises (TypeError , match = msg ):
45
56
com .pandas_dtype (box )
46
57
58
+ @pytest .mark .parametrize ("cls" , ALL_EA_DTYPES )
59
+ def test_raises_for_dtype_class (self , cls : type [ExtensionDtype ]):
60
+ msg = "Must pass dtype instance, not dtype class"
61
+ with pytest .raises (TypeError , match = msg ):
62
+ com .pandas_dtype (cls )
63
+
47
64
@pytest .mark .parametrize (
48
65
"dtype" ,
49
66
[
50
67
object ,
51
- "float64" ,
52
68
np .object_ ,
53
69
np .dtype ("object" ),
54
70
"O" ,
55
- np .float64 ,
56
71
float ,
72
+ np .float64 ,
57
73
np .dtype ("float64" ),
74
+ "float64" ,
58
75
],
59
76
)
60
77
def test_pandas_dtype_valid (self , dtype ):
@@ -106,48 +123,6 @@ def test_period_dtype(self, dtype):
106
123
assert com .pandas_dtype (dtype ) == PeriodDtype (dtype )
107
124
assert com .pandas_dtype (dtype ) == dtype
108
125
109
- @pytest .mark .parametrize (
110
- "cls" ,
111
- (
112
- pd .BooleanDtype ,
113
- pd .Int8Dtype ,
114
- pd .Int16Dtype ,
115
- pd .Int32Dtype ,
116
- pd .Int64Dtype ,
117
- pd .UInt8Dtype ,
118
- pd .UInt16Dtype ,
119
- pd .UInt32Dtype ,
120
- pd .UInt64Dtype ,
121
- pd .Float32Dtype ,
122
- pd .Float64Dtype ,
123
- pd .SparseDtype ,
124
- pd .StringDtype ,
125
- IntervalDtype ,
126
- CategoricalDtype ,
127
- pytest .param (
128
- DatetimeTZDtype ,
129
- marks = pytest .mark .xfail (reason = "must specify TZ" , raises = TypeError ),
130
- ),
131
- pytest .param (
132
- PeriodDtype ,
133
- marks = pytest .mark .xfail (
134
- reason = "must specify frequency" , raises = AttributeError
135
- ),
136
- ),
137
- ),
138
- )
139
- def test_pd_extension_dtype (self , cls ):
140
- """
141
- TODO: desired behavior?
142
-
143
- For extension dtypes that admit no options OR can be initialized with no args
144
- passed, convert the extension dtype class to an instance of that class.
145
- """
146
- expected = cls ()
147
- result = com .pandas_dtype (cls )
148
-
149
- assert result == expected
150
-
151
126
152
127
dtypes = {
153
128
"datetime_tz" : com .pandas_dtype ("datetime64[ns, US/Eastern]" ),
@@ -625,7 +600,6 @@ def test_is_bool_dtype_returns_false(value):
625
600
bool ,
626
601
np .bool_ ,
627
602
np .dtype (np .bool_ ),
628
- pd .BooleanDtype ,
629
603
pd .BooleanDtype (),
630
604
"bool" ,
631
605
"boolean" ,
@@ -731,7 +705,6 @@ def test_is_complex_dtype():
731
705
(PeriodDtype (freq = "D" ), PeriodDtype (freq = "D" )),
732
706
("period[D]" , PeriodDtype (freq = "D" )),
733
707
(IntervalDtype (), IntervalDtype ()),
734
- (pd .BooleanDtype , pd .BooleanDtype ()),
735
708
(pd .BooleanDtype (), pd .BooleanDtype ()),
736
709
],
737
710
)
0 commit comments