-
Notifications
You must be signed in to change notification settings - Fork 176
perf: make to_py_scalar 3x faster when argument is str #1276
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
perf: make to_py_scalar 3x faster when argument is str #1276
Conversation
|
@EdAbati fancy taking a look? |
FBruzzesi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commenting from mobile, just have a tiny question :)
FBruzzesi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick adjustment @MarcoGorelli 🙌🏼🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @MarcoGorelli, I like to see/learn about ways to speed up code
so checking number.Number early on would cause numpy scalars to not be converted to Python scalars
should we also add (np.int64(1), 1) in the tests to capture this? (at the moment that is indirectly tested in the doctests)
and the rest looks great!
| if item in {"to_py_scalar"}: | ||
| # We don't overwrite the docstring for these |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just so I know what to do/review in the future, which kind of methods should be added here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all of them to be honest, it's probably simpler to just use import narwhals as nw in all docstrings and forget about this test 😅 i'll make a separate pr
|
|
||
| T = TypeVar("T") | ||
|
|
||
| NON_TEMPORAL_SCALAR_TYPES = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of related, I am running a test, and getting a raise if None enters this function. Should we add it to non temporal scalar types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very good point, thanks!
|
really useful comments here, thanks both for excellent reviews 🙏 |


pretty consistent difference here:
main:
here:
What type of PR is this? (check all applicable)
Related issues
Checklist
If you have comments or can explain your changes, please do so below.