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

BUG: str.startswith and str.endswith with tuple argument fail for "string[pyarrow]" #54942

Closed
3 tasks done
ChronoJon opened this issue Sep 1, 2023 · 0 comments · Fixed by #54943
Closed
3 tasks done
Labels
Bug Strings String extension data type and string data

Comments

@ChronoJon
Copy link
Contributor

Pandas version checks

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

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
from IPython.display import display

values = ["a", None, "b"]
tuple_arg = ("a", "b")
o = pd.Series(values, dtype=object)
s = pd.Series(values, dtype="string")
a = pd.Series(values, dtype="string[pyarrow]")

display(
    o.str.startswith(tuple_arg),
    s.str.startswith(tuple_arg),
)
try:
    display(
        a.str.startswith(tuple_arg)
    )
except TypeError as e:
    display(e)  # TypeError('expected bytes, tuple found')

Issue Description

str.startswith and str.endswith methods support arguments of type tuple[str, ...]. For dtype "string[pyarrow]" this raises a type error. I've already written a fix and provide a pull request soon.

Expected Behavior

Don't throw an error and exhibit same behaviour as the object type string array and the pandas string extension array.

Installed Versions

pd.show_versions() INSTALLED VERSIONS ------------------ commit : ba1cccd19da778f0c3a7d6a885685da16a072870 python : 3.11.4.final.0 python-bits : 64 OS : Linux OS-release : 5.15.90.1-microsoft-standard-WSL2 Version : #1 SMP Fri Jan 27 02:56:13 UTC 2023 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 2.1.0
numpy : 1.25.2
pytz : 2023.3
dateutil : 2.8.2
setuptools : 68.0.0
pip : 23.2.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.1.2
lxml.etree : 4.9.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.14.0
pandas_datareader : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 12.0.1
pyreadstat : None
pyxlsb : 1.0.10
s3fs : None
scipy : 1.11.1
sqlalchemy : 2.0.20
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

@ChronoJon ChronoJon added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 1, 2023
ChronoJon added a commit to ChronoJon/pandas that referenced this issue Sep 1, 2023
ChronoJon added a commit to ChronoJon/pandas that referenced this issue Sep 5, 2023
ChronoJon added a commit to ChronoJon/pandas that referenced this issue Sep 6, 2023
@rhshadrach rhshadrach added Strings String extension data type and string data and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 7, 2023
ChronoJon added a commit to ChronoJon/pandas that referenced this issue Oct 10, 2023
mroeschke added a commit that referenced this issue Oct 23, 2023
…ng[pyarrow]"` dtype (GH#54942) (#54943)

* TST: added failing tuple tests for `str.startswith` and `str.startswith` (#54942)

* FIX: added fix for `str.startswith` and `str.endswith` with tuple arg for `"string[pyarrow]"` dtype (GH#54942)

* DOCS: added entry to whatsnew

* DOCS: moved contrib note to `Strings` section and fixed typos

* PERF: exchanged boolean array creation to method with less overhead

* CLN: removed unnecessary type checks

* DOCS: removed extra space before GH reference

---------

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Strings String extension data type and string data
Projects
None yet
2 participants