-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
ENH: add BooleanArray extension array #29555
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
640dac9
b9597bb
fa77b7a
29415a9
c4a53f2
b1182bc
94c5a90
1861602
ad6c477
67bf21a
f153fb2
e24c097
f0d0c6e
a3e1e93
1717583
5ce67e2
8c0abe6
031a113
90558d6
af82754
0eb3ca2
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 |
---|---|---|
|
@@ -130,11 +130,27 @@ def coerce_to_array(values, mask=None, copy=False): | |
if copy: | ||
values = values.copy() | ||
else: | ||
# TODO conversion from integer/float ndarray can be done more efficiently | ||
# (avoid roundtrip through object) | ||
values_object = np.asarray(values, dtype=object) | ||
|
||
inferred_dtype = lib.infer_dtype(values_object, skipna=True) | ||
integer_like = ("floating", "integer", "mixed-integer-float") | ||
if inferred_dtype not in ("boolean", "empty") + integer_like: | ||
raise TypeError("Need to pass bool-like values") | ||
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. tests hit here? 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.
Yes, there is a test that passes all kinds of non-boolean-like values In general, I ran locally pytest with coverage, and there is 97% coverage for this file. The main non-covered things are some parts of the ufunc related code, and some length mismatch errors in the ops code. |
||
|
||
mask_values = isna(values_object) | ||
values = np.zeros(len(values), dtype=bool) | ||
values[~mask_values] = values_object[~mask_values].astype(bool) | ||
|
||
# if the values were integer-like, validate it were actually 0/1's | ||
TomAugspurger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if inferred_dtype in integer_like: | ||
if not np.all( | ||
values[~mask_values].astype(float) | ||
== values_object[~mask_values].astype(float) | ||
): | ||
raise TypeError("Need to pass bool-like values") | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if mask is None and mask_values is None: | ||
mask = np.zeros(len(values), dtype=bool) | ||
elif mask is None: | ||
|
Uh oh!
There was an error while loading. Please reload this page.