-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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: pd.Series.isnumeric()
doesn't work on decimal value strings
#60750
BUG: pd.Series.isnumeric()
doesn't work on decimal value strings
#60750
Comments
pd.Series.isnumeric()
doesn't work on decimal value strings
Hi @sf-dcp, This is not a bug in
Numeric characters are those with the Unicode property values:
Therefore, Solution 01 - Using regeximport re
def is_numeric(string):
pattern = r'^-?\d+(\.\d+)?$'
return bool(re.match(pattern, string)) Note:
Solution 02 - Using
|
Hi @akj2018, thanks for the prompt reply and suggestions. I think the method name is a bit misleading then where I would expect a string number (with a dot or a negative integer string) to be returned |
Thanks for the report! This mirrors Python behavior: print("1.2".isnumeric())
# False The first line of the docstring states:
Are you saying there might be some confusion as to whether |
@rhshadrach, yep, I may be biased here but I can interpret |
I'd be okay with this addition. PRs are welcome! |
take |
Hi, |
Hi @JyotiP24 , |
what if we try this code ?
|
I noticed that pd.Series.isnumeric() currently returns False for '3.14' due to the behavior of Python’s str.isnumeric(). Would the intended fix be to have isnumeric() return True for strings that represent valid decimal numbers? Also, should we extend this to handle signs (like -3.14) or scientific notation (like 1e3), or keep it simple? |
No, pandas' |
Is this issue still open i want to contribute to this issue .Please assign me this issue . |
Hi @pranavgudagi , |
@forbid_nonstring_types(['bytes'])
def isnumeric(self, extended=False):
if extended:
regex = r'^[+-]?(\d+([.]\d*)?([eE][+-]?\d+)?|[.]\d+([eE][+-]?\d+)?)$'
return self._data.str.match(regex, na=False)
return self._data._str_map(
fname="isnumeric", dtype=np.dtype("bool"), na_value=False
) would this be a good solution to handling decimal strings? |
@akj2018 Are You still working on this? |
As mentioned, we should not change the code, this bug is a documentation fixing issue
|
Hey @akj2018 It's been 2 weeks, can you confirm if you are still working on it or if I can take the issue ? |
Hi @Anurag-Varma, Yes, I am still working on it. Due to health related concerns, I was not able to complete it. I will make a PR today without further delay. In future, please me mindful to wait for a while before taking an action. Thanks |
It's been 3 weeks since your last update on PR and 2 weeks ago you have mentioned that you are still working. I didn't find any updates on your remote repository in your account related to this issue so I just took it. But if you are still working then you can continue and send a PR. |
@Anurag-Varma Yes, because I haven't updated the remote with my local changes. Kindly refer the contribution guide in such situations, which mentions to ask the assigne along with period of inactivity. https://pandas.pydata.org/docs/development/contributing.html#finding-an-issue-to-contribute-to Rest assured that I will making a PR today so there is no further delay. |
…lude decimal, fraction, negatives and exponents (#60750) (#60960) * Improve examples for Series.str.isnumeric shared docstring to include fraction, decimals, negatives and exponents * Fixed trailing white space issue using pre-commit hook * DOC: Explicity mentioned type of Unicode numeric property in shared docstring for Series.str.isnumeric
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
Issue Description
The series method
.isnumeric()
only works on integer strings. If a string number is decimal, it will returnFalse
. When running the example below, the following is returned:This is the docs description for the method:
Expected Behavior
Running the method on decimal strings should return
True
.Installed Versions
INSTALLED VERSIONS
commit : 0691c5c
python : 3.12.8
python-bits : 64
OS : Linux
OS-release : 5.15.49-linuxkit-pr
Version : #1 SMP PREEMPT Thu May 25 07:27:39 UTC 2023
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : C.UTF-8
pandas : 2.2.3
numpy : 2.2.1
pytz : 2024.2
dateutil : 2.9.0.post0
pip : 24.3.1
Cython : None
sphinx : None
IPython : 8.31.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.5
lxml.etree : 5.3.0
matplotlib : 3.10.0
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.5
pandas_gbq : None
psycopg2 : 2.9.10
pymysql : None
pyarrow : 18.1.0
pyreadstat : None
pytest : 8.3.4
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.15.1
sqlalchemy : 2.0.37
tables : None
tabulate : 0.9.0
xarray : None
xlrd : 2.0.1
xlsxwriter : None
zstandard : None
tzdata : 2024.2
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: