-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: maybe_convert_objects add boolean support with NA #50047
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 all commits
3d6958d
48f41a2
43545c5
1ed72bf
62c798f
85c995a
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 |
---|---|---|
|
@@ -1309,10 +1309,14 @@ cdef class Seen: | |
@property | ||
def is_bool(self): | ||
# i.e. not (anything but bool) | ||
return not ( | ||
self.datetime_ or self.datetimetz_ or self.timedelta_ or self.nat_ | ||
or self.period_ or self.interval_ | ||
or self.numeric_ or self.nan_ or self.null_ or self.object_ | ||
return self.is_bool_or_na and not (self.nan_ or self.null_) | ||
|
||
@property | ||
def is_bool_or_na(self): | ||
# i.e. not (anything but bool or missing values) | ||
return self.bool_ and not ( | ||
self.datetime_ or self.datetimetz_ or self.nat_ or self.timedelta_ | ||
or self.period_ or self.interval_ or self.numeric_ or self.object_ | ||
) | ||
|
||
|
||
|
@@ -2335,7 +2339,7 @@ def maybe_convert_objects(ndarray[object] objects, | |
bint convert_timedelta=False, | ||
bint convert_period=False, | ||
bint convert_interval=False, | ||
bint convert_to_nullable_integer=False, | ||
bint convert_to_nullable_dtype=False, | ||
object dtype_if_all_nat=None) -> "ArrayLike": | ||
""" | ||
Type inference function-- convert object array to proper dtype | ||
|
@@ -2362,9 +2366,9 @@ def maybe_convert_objects(ndarray[object] objects, | |
convert_interval : bool, default False | ||
If an array-like object contains only Interval objects (with matching | ||
dtypes and closedness) or NaN, whether to convert to IntervalArray. | ||
convert_to_nullable_integer : bool, default False | ||
If an array-like object contains only integer values (and NaN) is | ||
encountered, whether to convert and return an IntegerArray. | ||
convert_to_nullable_dtype : bool, default False | ||
If an array-like object contains only integer or boolean values (and NaN) is | ||
encountered, whether to convert and return an Boolean/IntegerArray. | ||
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. Just to confirm 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. This is something I raised in the sql pr as well. Currently, we only use ea, when the regular dtype can’t hold missing values. So there is no real use case for FloatArray. it would probably make more sense to always convert when this flag is set, but this is out of scope 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. Yeah. I would opt to returning But sure can be a follow up |
||
dtype_if_all_nat : np.dtype, ExtensionDtype, or None, default None | ||
Dtype to cast to if we have all-NaT. | ||
|
||
|
@@ -2446,7 +2450,7 @@ def maybe_convert_objects(ndarray[object] objects, | |
seen.int_ = True | ||
floats[i] = <float64_t>val | ||
complexes[i] = <double complex>val | ||
if not seen.null_ or convert_to_nullable_integer: | ||
if not seen.null_ or convert_to_nullable_dtype: | ||
seen.saw_int(val) | ||
|
||
if ((seen.uint_ and seen.sint_) or | ||
|
@@ -2606,6 +2610,9 @@ def maybe_convert_objects(ndarray[object] objects, | |
if seen.is_bool: | ||
# is_bool property rules out everything else | ||
return bools.view(np.bool_) | ||
elif convert_to_nullable_dtype and seen.is_bool_or_na: | ||
from pandas.core.arrays import BooleanArray | ||
return BooleanArray(bools.view(np.bool_), mask) | ||
jbrockmendel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
seen.object_ = True | ||
|
||
if not seen.object_: | ||
|
@@ -2617,7 +2624,7 @@ def maybe_convert_objects(ndarray[object] objects, | |
elif seen.float_: | ||
result = floats | ||
elif seen.int_ or seen.uint_: | ||
if convert_to_nullable_integer: | ||
if convert_to_nullable_dtype: | ||
from pandas.core.arrays import IntegerArray | ||
if seen.uint_: | ||
result = IntegerArray(uints, mask) | ||
|
Uh oh!
There was an error while loading. Please reload this page.