Skip to content

Commit c7cc800

Browse files
committed
test
1 parent b00ce10 commit c7cc800

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

pandas/_libs/lib.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,6 @@ def infer_dtype(value: object, skipna: bool = True) -> str:
16951695
if is_interval_array(values):
16961696
return "interval"
16971697

1698-
print("infer_dtype")
16991698
reg_dtype = _registry.match_scalar(val)
17001699
if reg_dtype:
17011700
return str(reg_dtype)

pandas/core/dtypes/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,17 @@ def _can_fast_transpose(self) -> bool:
444444
"""
445445
return False
446446

447-
def is_unambiguous_scalar(self):
447+
@classmethod
448+
def is_unambiguous_scalar(cls, scalar):
448449
return False
449450

450451
@classmethod
451452
def construct_from_scalar(cls, scalar):
452453
return cls()
454+
455+
@property
456+
def is_external_dtype(self) -> bool:
457+
return not self.__module__.split(".")[0] == "pandas"
453458

454459

455460
class StorageExtensionDtype(ExtensionDtype):

pandas/core/dtypes/cast.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,8 @@ def infer_dtype_from_array(arr) -> tuple[DtypeObj, ArrayLike]:
918918
inferred = lib.infer_dtype(arr, skipna=False)
919919
if inferred in ["string", "bytes", "mixed", "mixed-integer"]:
920920
return (np.dtype(np.object_), arr)
921+
elif inferred in ["empty", "integer", "floating", "integer-na", "mixed-integer-float", "datetime", "period", "timedelta", "time", "date"]:
922+
pass
921923
else:
922924
arr_dtype = pandas_dtype_func(inferred)
923925
if isinstance(arr_dtype, ExtensionDtype):

pandas/core/series.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,10 @@ def __init__(
502502
data = data.copy()
503503
else:
504504
if dtype is None:
505-
dtype = infer_dtype_from(data)[0]
505+
inferred_dtype = infer_dtype_from(data)[0]
506+
if isinstance(inferred_dtype, ExtensionDtype) and inferred_dtype.is_external_dtype:
507+
dtype = inferred_dtype
508+
# import pdb; pdb.set_trace()
506509
data = sanitize_array(data, index, dtype, copy)
507510
data = SingleBlockManager.from_array(data, index, refs=refs)
508511

pandas/tests/dtypes/test_inference.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@
8181
def coerce(request):
8282
return request.param
8383

84+
class MockScalar:
85+
pass
86+
87+
class MockDtype(pd.api.extensions.ExtensionDtype):
88+
89+
90+
8491

8592
class MockNumpyLikeArray:
8693
"""

0 commit comments

Comments
 (0)