Skip to content

BUG: any() and all() behavior on string series is different from python #36880

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
2 of 3 tasks
ThewBear opened this issue Oct 5, 2020 · 4 comments
Closed
2 of 3 tasks
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@ThewBear
Copy link

ThewBear commented Oct 5, 2020

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

pd.Series(["kkkk", "llll"]).any() # "kkkk"
any(["kkkk", "llll"]) # True

pd.Series(["kkkk", "llll"]).all() # "llll"
all(["kkkk", "llll"]) # True

Problem description

Python returns boolean not the value. So we should follow that.
https://stackoverflow.com/questions/10180344/why-does-python-any-return-a-bool-instead-of-the-value

Expected Output

The expected behavior is to match any and all built-in functions.

https://docs.python.org/3/library/functions.html#any

def any(iterable):
    for element in iterable:
        if element:
            return True
    return False

https://docs.python.org/3/library/functions.html#all

def all(iterable):
    for element in iterable:
        if not element:
            return False
    return True

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2a7d332
python : 3.7.8.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.112+
Version : #⁠1 SMP Fri Sep 4 12:06:06 PDT 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.2
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.2.0.post20200712
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.1.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : 1.3.18
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@ThewBear ThewBear added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 5, 2020
@rhshadrach
Copy link
Member

pandas calls any and all on the corresponding ndarray.

s = np.asarray(["kkkk", "llll"], dtype=np.object)
print(s.any())

also results in "kkkk". I don't know if there is a particular reason numpy (and hence, pandas) does this.

@gimseng
Copy link
Contributor

gimseng commented Oct 8, 2020

This seems to have happened before in #12863 (see also #30416).

I don't get the impression that its fixed though, so we either can figure out what's going on here or close this and continue the discussion there.

@gimseng
Copy link
Contributor

gimseng commented Oct 8, 2020

On numpy, a related issue.

@TomAugspurger
Copy link
Contributor

Let's close in favor of #12863 / numpy/numpy#11857 to keep the discussion in one place (per project).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

4 participants