-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
ENH: general concat with ExtensionArrays through find_common_type #33607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3464e95
b1d9d68
bb398e7
83fdc91
7f2ac2a
d0f90de
2d5fcb0
a68206b
fc98b65
b072591
91c984a
2a2b9d5
8893165
e19e3ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,16 @@ def _cast_to_common_type(arr: ArrayLike, dtype: DtypeObj) -> ArrayLike: | |
except ValueError: | ||
return arr.astype(object, copy=False) | ||
|
||
if ( | ||
isinstance(arr, np.ndarray) | ||
and arr.dtype.kind in ["m", "M"] | ||
and dtype is np.dtype("object") | ||
): | ||
# wrap datetime-likes in EA to ensure astype(object) gives Timestamp/Timedelta | ||
# this can happen when concat_compat is called directly on arrays (when arrays | ||
# are not coming from Index/Series._values), eg in BlockManager.quantile | ||
arr = array(arr) | ||
|
||
if is_extension_array_dtype(dtype): | ||
if isinstance(arr, np.ndarray): | ||
# numpy's astype cannot handle ExtensionDtypes | ||
|
@@ -123,7 +133,6 @@ def is_nonempty(x) -> bool: | |
|
||
typs = get_dtype_kinds(to_concat) | ||
_contains_datetime = any(typ.startswith("datetime") for typ in typs) | ||
_contains_period = any(typ.startswith("period") for typ in typs) | ||
|
||
all_empty = not len(non_empties) | ||
single_dtype = len({x.dtype for x in to_concat}) == 1 | ||
|
@@ -140,7 +149,7 @@ def is_nonempty(x) -> bool: | |
else: | ||
return np.concatenate(to_concat) | ||
|
||
elif _contains_datetime or "timedelta" in typs or _contains_period: | ||
elif _contains_datetime or "timedelta" in typs: | ||
return concat_datetime(to_concat, axis=axis, typs=typs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we do the DTA/TDA casting above, and do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, because they are not using ExtensionDtype. |
||
|
||
elif any_ea and axis == 1: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 quality comment