-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DEPR: concat ignoring empty objects #52532
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 6 commits
63292d4
2ace79c
6258adf
bfd969f
51e6d36
52ce0d7
f8dc81e
163bf8a
03a0641
49a7146
7e2e995
7c0c715
7f2977a
0eaf359
a878fea
75d5041
9e2de8f
392b40a
465c141
3666bca
390d4ef
aa5794f
1277b26
5cddae9
8e58bff
47a17b3
e696c53
7f07121
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,12 @@ | |
Sequence, | ||
cast, | ||
) | ||
import warnings | ||
|
||
import numpy as np | ||
|
||
from pandas._libs import lib | ||
from pandas.util._exceptions import find_stack_level | ||
|
||
from pandas.core.dtypes.astype import astype_array | ||
from pandas.core.dtypes.cast import ( | ||
|
@@ -42,6 +44,9 @@ | |
) | ||
|
||
|
||
_dtype_obj = np.dtype(object) | ||
|
||
|
||
def _is_nonempty(x, axis) -> bool: | ||
# filter empty arrays | ||
# 1-d dtypes always are included here | ||
|
@@ -104,6 +109,22 @@ def concat_compat( | |
non_empties = [x for x in to_concat if _is_nonempty(x, axis)] | ||
if non_empties and axis == 0 and not ea_compat_axis: | ||
# ea_compat_axis see GH#39574 | ||
if len(non_empties) < len(to_concat) and not any( | ||
obj.dtype == _dtype_obj for obj in non_empties | ||
): | ||
# Check for object dtype is an imperfect proxy for checking if | ||
# the result dtype is going to change once the deprecation is | ||
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. Can't we verify this exactly? (checking what the common dtype would be with or without the empties?) Because I think the check above will easily give false positives (unless I am misreading it): for example, for just a mixture of int types, of which one is empty, will trigger the warning? (since none of them is object dtype) While it will typically not change the resulting dtype (except if the input arrays with the largest bitwidth are all empty) 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. Worth a try! Will take a look |
||
# enforced. | ||
# GH#39122 | ||
warnings.warn( | ||
"The behavior of array concatenation with empty entries is " | ||
"deprecated. In a future version, this will no longer exclude " | ||
"empty items when determining the result dtype. " | ||
"To retain the old behavior, exclude the empty entries before " | ||
"the concat operation.", | ||
FutureWarning, | ||
stacklevel=find_stack_level(), | ||
) | ||
to_concat = non_empties | ||
|
||
dtypes = {obj.dtype for obj in to_concat} | ||
|
Uh oh!
There was an error while loading. Please reload this page.