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: String methods has no method "isascii()" #59091

Open
3 tasks done
ujex256 opened this issue Jun 25, 2024 · 5 comments · May be fixed by #60532
Open
3 tasks done

BUG: String methods has no method "isascii()" #59091

ujex256 opened this issue Jun 25, 2024 · 5 comments · May be fixed by #60532
Assignees
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@ujex256
Copy link

ujex256 commented Jun 25, 2024

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
series = pd.Series(["a", "b", "c", "あ", ""])

series.str.isalnum()
"""
0    True
1    True
2    True
3    True
4    False
dtype: bool
"""

series.str.isascii()
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
# AttributeError: 'StringMethods' object has no attribute 'isascii'

Issue Description

pd.Series.str does not support isascii() metod.

Expected Behavior

The code shown above would look like this.

series.str.isascii()
"""
0    True
1    True
2    True
3    False
4    True
dtype: bool
"""

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.11.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22631
machine : AMD64
processor : Intel64 Family 6 Model 151 Stepping 2, GenuineIntel
byteorder : little
LC_ALL : None
LANG : ja_JP.UTF-8
LOCALE : Japanese_Japan.932

pandas : 2.2.2
numpy : 2.0.0
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 69.5.1
pip : 24.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 5.2.2
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.25.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None

@ujex256 ujex256 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 25, 2024
@krishsharma0413
Copy link

Can a contributor look into this and if needed I will work on the PR :P
unless @ujex256 or someone else is already working on it.

@ujex256
Copy link
Author

ujex256 commented Jun 25, 2024

@krishsharma0413
Thank you for your help!
I was already trying to get the PR out.
I appreciate your concern.

@Siddharth-Latthe-07
Copy link

@ujex256 The pd.Series.str accessor in pandas does not have an isascii method by default. However, you can achieve the desired functionality by using a custom function combined with the apply method.

import pandas as pd

def is_ascii(s):
    return all(ord(c) < 128 for c in s)

series = pd.Series(["a", "b", "c", "あ", ""])

series_isascii = series.apply(is_ascii)
print(series_isascii)
"""
0     True
1     True
2     True
3    False
4     True
dtype: bool
"""

let me know, if it works
Thanks

@yuanx749
Copy link
Contributor

I think this is more of a Feature Request rather than a bug.

A temporary workaround could be series.apply(lambda x: x.isascii()).

@avecasey
Copy link

avecasey commented Dec 8, 2024

take

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
5 participants