Skip to content

BUG: Series.any/all with level keyword should preserve boolean dtype #33449

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

Closed
jorisvandenbossche opened this issue Apr 10, 2020 · 3 comments · Fixed by #40819
Closed

BUG: Series.any/all with level keyword should preserve boolean dtype #33449

jorisvandenbossche opened this issue Apr 10, 2020 · 3 comments · Fixed by #40819
Labels
Bug NA - MaskedArrays Related to pd.NA and nullable extension arrays Reduction Operations sum, mean, min, max, etc.
Milestone

Comments

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Apr 10, 2020

In [5]: s = pd.Series([False, False, True, True, False, True],
                      index=[0, 0, 1, 1, 2, 2], dtype="boolean")  

In [6]: s.all(level=0) 
Out[6]: 
0    False
1     True
2    False
dtype: bool

The dtype of the result could also be boolean instead of bool.

@jorisvandenbossche jorisvandenbossche added Bug NA - MaskedArrays Related to pd.NA and nullable extension arrays labels Apr 10, 2020
@jorisvandenbossche jorisvandenbossche added this to the Contributions Welcome milestone Apr 10, 2020
@KenilMehta
Copy link
Contributor

Hi @jorisvandenbossche
This is my first Pandas Issue and I would like to help solve this issue.

Just for understanding the issue, the dtype of the Series object is "boolean", hence, we want the return type of Series.all() also to be "boolean" instead of "bool". Is that right?

@jorisvandenbossche
Copy link
Member Author

Yes, that is correct. But specifically with the level keyword as in the example above. Without using the level keyword, it already works as expected.

@KenilMehta
Copy link
Contributor

Do we want the dtype of result Series to match with the original Series in all the cases or only in the case of boolean?

What would you expect the dtype of result Series to be in the following example?

import pandas as pd
import numpy as np

s = pd.Series([0, 0, 1, 1, 0, 1], index=[0, 0, 1, 1, 2, 2], dtype="int64")
print(s.all(level=0))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug NA - MaskedArrays Related to pd.NA and nullable extension arrays Reduction Operations sum, mean, min, max, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants