Skip to content

Closes-2915, adds isnumeric function - #4694

Merged
ajpotts merged 4 commits into
Bears-R-Us:masterfrom
drculhane:Closes-2915
Jul 21, 2025
Merged

ajpotts merged 4 commits into
Bears-R-Us:masterfrom
drculhane:Closes-2915

Conversation

@drculhane

@drculhane drculhane commented Jul 2, 2025 •

Copy link
Copy Markdown
Contributor

Update

--

The current revision (as of 7/10/25) moves isnumeric into the char folder. It can now be addressed in three ways:

pda.isnumeric(), that is, as a method of the pdarray class
ak.char.isnumeric(pda), similar to np.char.isnumeric, and
ak.isnumeric(pda), and I'm not sure why that works.

arkouda/numpy/char.py has only the isnumeric function. Its input is String, but when I import strings at the top of the file in order to use typechecking, I get a circular import. The only way I found to avoid that was not to use @typecheck, and instead to import strings inside the function, and manually do the type check there.

--

I've implemented Ryan's suggestion to use a set instead of an array to store the known numeric unicodes. I tried to search through all the letters in a string with a forall, but I kept getting this error message:

/home/drandy/projects/arkouda/src/SegmentedString.chpl:1776: error: A standalone or leader iterator is not found for the iterable expression in this forall loop
make: *** [Makefile:569: arkouda_server] Error 1

I understand that message, but it doesn't seem applicable, since it refers to zipped iterations, which I don't think this is.

--

I've done a major rewrite of this, such that it now covers all the cases that np.char.isnumeric() considers numeric (a total of 1922 characters, including decimal digits, numerical superscripts and subscripts, special characters with digits encircled or enclosed in parens, "vulgar fractions," non-Arabic numerals, etc).

The function is now a string method (in strings.py, not numeric.py), so it's addressed the same way the other string methods are, e.g.

stringName.isdigit()
stringName.isdecimal()
stringName.isnumeric()

It's also accessible as a standalone function, ak.isnumeric().

--

Closes #2915, adding an isnumeric function to match np.char.isnumeric.

Note:

This is presently in arkouda/numpy/numeric.py, but maybe it belongs in strings.py? [That's where it is now.]

There is no multi-dim test, because arkouda, AFAIK, doesn't support multi-dim string pdarrays. String pdarrays are actually segmented strings.

The SegString class already had a method isdigits, which I was able to use to implement isnumeric. [outdated. The class now has an isnumeric method.]

@drculhane
drculhane marked this pull request as draft July 2, 2025 20:54
@drculhane
drculhane force-pushed the Closes-2915 branch 4 times, most recently from b943f2d to c6604e5 Compare July 3, 2025 19:25
@drculhane
drculhane marked this pull request as ready for review July 3, 2025 23:17

@1RyanK 1RyanK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will work, but would it be too much to change the array of hex things into a set? Then instead of doing a forall comparing the things in the set to the current character, you can just see if the set contains the character, and do a forall over the strings or characters (or both? I think if you do both, then it works whether you have few strings with many characters each, or many strings with few characters each).

@drculhane

drculhane commented Jul 7, 2025 •

Copy link
Copy Markdown
Contributor Author

I really like this suggestion. I'll push a revision later this morning.

Done.

@1RyanK 1RyanK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so after looking into it, parallelizing over a single string is not really something the compiler likes to do, thus the compiler error.
However, one other thing - I'm concerned that every time the function is called, it creates that big var set and checks to see if the character is in it. Instead, could you try declaring it outside the function, and declaring as const? It doesn't change so that may help performance. Other than that, I don't think there's anything practical that can be done.

@drculhane

Copy link
Copy Markdown
Contributor Author

Okay, so after looking into it, parallelizing over a single string is not really something the compiler likes to do, thus the compiler error. However, one other thing - I'm concerned that every time the function is called, it creates that big var set and checks to see if the character is in it. Instead, could you try declaring it outside the function, and declaring as const? It doesn't change so that may help performance. Other than that, I don't think there's anything practical that can be done.

Also an excellent suggestion. Done.

@ajpotts
ajpotts requested a review from e-kayrakli July 7, 2025 16:48
Comment thread arkouda/numpy/strings.py Resolved
Comment thread arkouda/numpy/strings.py Resolved
Comment thread arkouda/numpy/strings.py Resolved
Comment thread tests/numpy/string_test.py Resolved

@ajpotts ajpotts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@drculhane
drculhane force-pushed the Closes-2915 branch 2 times, most recently from 1de862f to d59e84a Compare July 9, 2025 12:49
@ajpotts
ajpotts added this pull request to the merge queue Jul 15, 2025
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 15, 2025
@ajpotts
ajpotts added this pull request to the merge queue Jul 21, 2025
Merged via the queue into Bears-R-Us:master with commit 97bd9a2 Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add isnumeric function for pdarrays

3 participants