File tree Expand file tree Collapse file tree 5 files changed +37
-0
lines changed Expand file tree Collapse file tree 5 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,8 @@ from pandas._libs.tslibs.period cimport is_period_object
107
107
from pandas._libs.tslibs.timedeltas cimport convert_to_timedelta64
108
108
from pandas._libs.tslibs.timezones cimport tz_compare
109
109
110
+ from pandas.core.dtypes.base import _registry
111
+
110
112
# constants that will be compared to potentially arbitrarily large
111
113
# python int
112
114
cdef:
@@ -1693,6 +1695,11 @@ def infer_dtype(value: object, skipna: bool = True) -> str:
1693
1695
if is_interval_array(values):
1694
1696
return " interval"
1695
1697
1698
+ print (" infer_dtype" )
1699
+ reg_dtype = _registry.match_scalar(val)
1700
+ if reg_dtype:
1701
+ return str (reg_dtype)
1702
+
1696
1703
cnp.PyArray_ITER_RESET(it)
1697
1704
for i in range (n):
1698
1705
val = PyArray_GETITEM(values, PyArray_ITER_DATA(it))
Original file line number Diff line number Diff line change @@ -370,6 +370,10 @@ def array(
370
370
371
371
elif data .dtype .kind == "b" :
372
372
return BooleanArray ._from_sequence (data , dtype = "boolean" , copy = copy )
373
+ # elif inferred_dtype != "mixed":
374
+ # dtype = pandas_dtype(inferred_dtype)
375
+ # cls = dtype.construct_array_type()
376
+ # return cls._from_sequence(data, dtype=dtype, copy=copy)
373
377
else :
374
378
# e.g. complex
375
379
return NumpyExtensionArray ._from_sequence (data , dtype = data .dtype , copy = copy )
Original file line number Diff line number Diff line change @@ -444,6 +444,13 @@ def _can_fast_transpose(self) -> bool:
444
444
"""
445
445
return False
446
446
447
+ def is_unambiguous_scalar (self ):
448
+ return False
449
+
450
+ @classmethod
451
+ def construct_from_scalar (cls , scalar ):
452
+ return cls ()
453
+
447
454
448
455
class StorageExtensionDtype (ExtensionDtype ):
449
456
"""ExtensionDtype that may be backed by more than one implementation."""
@@ -582,5 +589,13 @@ def find(
582
589
583
590
return None
584
591
592
+ def match_scalar (
593
+ self , scalar : Any
594
+ ) -> type_t [ExtensionDtype ] | ExtensionDtype | None :
595
+ for dtype in self .dtypes :
596
+ if dtype .is_unambiguous_scalar (scalar ):
597
+ return dtype .construct_from_scalar (scalar )
598
+ return None
599
+
585
600
586
601
_registry = Registry ()
Original file line number Diff line number Diff line change 44
44
LossySetitemError ,
45
45
)
46
46
47
+ from pandas .core .dtypes .base import _registry
47
48
from pandas .core .dtypes .common import (
48
49
ensure_int8 ,
49
50
ensure_int16 ,
@@ -857,6 +858,10 @@ def infer_dtype_from_scalar(val) -> tuple[DtypeObj, Any]:
857
858
subtype = infer_dtype_from_scalar (val .left )[0 ]
858
859
dtype = IntervalDtype (subtype = subtype , closed = val .closed )
859
860
861
+ reg_dtype = _registry .match_scalar (val )
862
+ if reg_dtype :
863
+ dtype = reg_dtype
864
+
860
865
return dtype , val
861
866
862
867
@@ -913,6 +918,10 @@ def infer_dtype_from_array(arr) -> tuple[DtypeObj, ArrayLike]:
913
918
inferred = lib .infer_dtype (arr , skipna = False )
914
919
if inferred in ["string" , "bytes" , "mixed" , "mixed-integer" ]:
915
920
return (np .dtype (np .object_ ), arr )
921
+ else :
922
+ arr_dtype = pandas_dtype_func (inferred )
923
+ if isinstance (arr_dtype , ExtensionDtype ):
924
+ return arr_dtype , arr
916
925
917
926
arr = np .asarray (arr )
918
927
return arr .dtype , arr
Original file line number Diff line number Diff line change @@ -501,6 +501,8 @@ def __init__(
501
501
elif copy :
502
502
data = data .copy ()
503
503
else :
504
+ if dtype is None :
505
+ dtype = infer_dtype_from (data )[0 ]
504
506
data = sanitize_array (data , index , dtype , copy )
505
507
data = SingleBlockManager .from_array (data , index , refs = refs )
506
508
You can’t perform that action at this time.
0 commit comments