File tree 3 files changed +27
-11
lines changed
3 files changed +27
-11
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,11 @@ from cpython.datetime cimport (
13
13
PyDateTime_Check,
14
14
PyDelta_Check,
15
15
PyTime_Check,
16
+ date,
17
+ datetime,
16
18
import_datetime,
19
+ time,
20
+ timedelta,
17
21
)
18
22
from cpython.iterator cimport PyIter_Check
19
23
from cpython.number cimport PyNumber_Check
@@ -1204,6 +1208,12 @@ _TYPE_MAP = {
1204
1208
" m" : " timedelta64" ,
1205
1209
" interval" : " interval" ,
1206
1210
Period: " period" ,
1211
+ datetime: " datetime64" ,
1212
+ date: " date" ,
1213
+ time: " time" ,
1214
+ timedelta: " timedelta64" ,
1215
+ Decimal: " decimal" ,
1216
+ bytes: " bytes" ,
1207
1217
}
1208
1218
1209
1219
# types only exist on certain platform
@@ -1373,7 +1383,8 @@ cdef object _try_infer_map(object dtype):
1373
1383
cdef:
1374
1384
object val
1375
1385
str attr
1376
- for attr in [" kind" , " name" , " base" , " type" ]:
1386
+ for attr in [" type" , " kind" , " name" , " base" ]:
1387
+ # Checking type before kind matters for ArrowDtype cases
1377
1388
val = getattr (dtype, attr, None )
1378
1389
if val in _TYPE_MAP:
1379
1390
return _TYPE_MAP[val]
Original file line number Diff line number Diff line change 6
6
7
7
import pandas as pd
8
8
import pandas ._testing as tm
9
- from pandas .api .types import infer_dtype
10
9
from pandas .tests .extension import base
11
10
from pandas .tests .extension .decimal .array import (
12
11
DecimalArray ,
@@ -70,15 +69,7 @@ def data_for_grouping():
70
69
71
70
72
71
class TestDtype (base .BaseDtypeTests ):
73
- def test_hashable (self , dtype ):
74
- pass
75
-
76
- @pytest .mark .parametrize ("skipna" , [True , False ])
77
- def test_infer_dtype (self , data , data_missing , skipna ):
78
- # here overriding base test to ensure we fall back to return
79
- # "unknown-array" for an EA pandas doesn't know
80
- assert infer_dtype (data , skipna = skipna ) == "unknown-array"
81
- assert infer_dtype (data_missing , skipna = skipna ) == "unknown-array"
72
+ pass
82
73
83
74
84
75
class TestInterface (base .BaseInterfaceTests ):
Original file line number Diff line number Diff line change @@ -2905,3 +2905,17 @@ def test_duration_overflow_from_ndarray_containing_nat():
2905
2905
result = ser_ts + ser_td
2906
2906
expected = pd .Series ([2 , None ], dtype = ArrowDtype (pa .timestamp ("ns" )))
2907
2907
tm .assert_series_equal (result , expected )
2908
+
2909
+
2910
+ def test_infer_dtype_pyarrow_dtype (data , request ):
2911
+ res = lib .infer_dtype (data )
2912
+ assert res != "unknown-array"
2913
+
2914
+ if data ._hasna and res in ["floating" , "datetime64" , "timedelta64" ]:
2915
+ mark = pytest .mark .xfail (
2916
+ reason = "in infer_dtype pd.NA is not ignored in these cases "
2917
+ "even with skipna=True in the list(data) check below"
2918
+ )
2919
+ request .node .add_marker (mark )
2920
+
2921
+ assert res == lib .infer_dtype (list (data ), skipna = True )
You can’t perform that action at this time.
0 commit comments