Skip to content

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

Closed
@ThewBear

Description

@ThewBear
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions