File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -228,3 +228,4 @@ def get_reverse_indexer(
228
228
length : int ,
229
229
) -> npt .NDArray [np .intp ]: ...
230
230
def is_bool_list (obj : list ) -> bool : ...
231
+ def dtypes_all_equal (types : list [DtypeObj ]) -> bool : ...
Original file line number Diff line number Diff line change @@ -3038,3 +3038,25 @@ def is_bool_list(obj: list) -> bool:
3038
3038
3039
3039
# Note: we return True for empty list
3040
3040
return True
3041
+
3042
+
3043
+ def dtypes_all_equal (list types not None ) -> bool:
3044
+ """
3045
+ Faster version for:
3046
+
3047
+ first = types[0 ]
3048
+ all(is_dtype_equal(first , t ) for t in types[1:])
3049
+
3050
+ And assuming all elements in the list are np.dtype/ExtensionDtype objects
3051
+
3052
+ See timings at https://github.com/pandas-dev/pandas/pull/44594
3053
+ """
3054
+ first = types[0 ]
3055
+ for t in types[1:]:
3056
+ try:
3057
+ if not t == first:
3058
+ return False
3059
+ except (TypeError , AttributeError ):
3060
+ return False
3061
+ else :
3062
+ return True
Original file line number Diff line number Diff line change @@ -1815,7 +1815,7 @@ def find_common_type(types: list[DtypeObj]) -> DtypeObj:
1815
1815
1816
1816
# workaround for find_common_type([np.dtype('datetime64[ns]')] * 2)
1817
1817
# => object
1818
- if all ( is_dtype_equal ( first , t ) for t in types [ 1 :] ):
1818
+ if lib . dtypes_all_equal ( list ( types ) ):
1819
1819
return first
1820
1820
1821
1821
# get unique types (dict.fromkeys is used as order-preserving set())
You can’t perform that action at this time.
0 commit comments