Skip to content
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

ENH: should a sequence of integers be a valid input to BooleanArray? #37614

Open
arw2019 opened this issue Nov 3, 2020 · 3 comments
Open

ENH: should a sequence of integers be a valid input to BooleanArray? #37614

arw2019 opened this issue Nov 3, 2020 · 3 comments
Labels
Constructors Series/DataFrame/Index/pd.array Constructors Enhancement NA - MaskedArrays Related to pd.NA and nullable extension arrays Needs Discussion Requires discussion from core team before further action

Comments

@arw2019
Copy link
Member

arw2019 commented Nov 3, 2020

Came across this while working on #37377

xref #28778 for potentially relevant prior discussions

This works on NumPy:

In [10]: np.array([0, 1, 2], dtype=bool)
Out[10]: array([False,  True,  True])

but the following fails with BooleanArray:

In [11]: arr  = pd.array([0, 1, 2], dtype="boolean")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-11-44c03a9227eb> in <module>
----> 1 arr  = pd.array([0, 1, 2], dtype="boolean")

/workspaces/pandas/pandas/core/construction.py in array(data, dtype, copy)
    296     if is_extension_array_dtype(dtype):
    297         cls = cast(ExtensionDtype, dtype).construct_array_type()
--> 298         return cls._from_sequence(data, dtype=dtype, copy=copy)
    299 
    300     if dtype is None:

/workspaces/pandas/pandas/core/arrays/boolean.py in _from_sequence(cls, scalars, dtype, copy)
    276         if dtype:
    277             assert dtype == "boolean"
--> 278         values, mask = coerce_to_array(scalars, copy=copy)
    279         return BooleanArray(values, mask)
    280 

/workspaces/pandas/pandas/core/arrays/boolean.py in coerce_to_array(values, mask, copy)
    176                 == values_object[~mask_values].astype(float)
    177             ):
--> 178                 raise TypeError("Need to pass bool-like values")
    179 
    180     if mask is None and mask_values is None:

TypeError: Need to pass bool-like values

I'm +0 on supporting NumPy-like behavior here (or we should make sure to document the current behavior)

@arw2019 arw2019 added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 3, 2020
@YuRenee
Copy link

YuRenee commented Nov 9, 2020

take
I am new to this project and I would like to try on this issue.

@arw2019
Copy link
Member Author

arw2019 commented Nov 9, 2020

@YuRenee welcome to pandas!

I would suggest that you start by searching for tickets with the label "Good first issue". I don't think we've decided what we want to do on this one, yet.

@YuRenee
Copy link

YuRenee commented Nov 9, 2020

@YuRenee welcome to pandas!

I would suggest that you start by searching for tickets with the label "Good first issue". I don't think we've decided what we want to do on this one, yet.

sure! Thanks hahaha

@jbrockmendel jbrockmendel added API Design Constructors Series/DataFrame/Index/pd.array Constructors NA - MaskedArrays Related to pd.NA and nullable extension arrays and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 6, 2021
@mroeschke mroeschke added Needs Discussion Requires discussion from core team before further action and removed API Design labels Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Constructors Series/DataFrame/Index/pd.array Constructors Enhancement NA - MaskedArrays Related to pd.NA and nullable extension arrays Needs Discussion Requires discussion from core team before further action
Projects
None yet
Development

No branches or pull requests

4 participants