-
-
Notifications
You must be signed in to change notification settings - Fork 11k
DOC: added example in char #22500
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
DOC: added example in char #22500
Conversation
>>> np.char.add(["num", "doc"], ["py", "umentation"]) | ||
array(['numpy', 'documentation'], dtype='<U13') | ||
|
||
The methods in this module are based on the methods in :py:mod:`String` |
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.
alternatively: These methods are based on :py:mod:`String`
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 the examples won't fit on this page... As each method has its own page (when you click on hyperlinks - https://numpy.org/devdocs/reference/routines.char.html)
For example numpy.char.capitalize
already has an example listed on its doc page - https://numpy.org/devdocs/reference/generated/numpy.char.capitalize.html
May be adding examples to each method separately is a good idea to maintain consistency.
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.
You can shift the example for np.char.add into
numpy/numpy/core/defchararray.py
Lines 297 to 322 in 04ddeb3
@array_function_dispatch(_binary_op_dispatcher) | |
def add(x1, x2): | |
""" | |
Return element-wise string concatenation for two arrays of str or unicode. | |
Arrays `x1` and `x2` must have the same shape. | |
Parameters | |
---------- | |
x1 : array_like of str or unicode | |
Input array. | |
x2 : array_like of str or unicode | |
Input array. | |
Returns | |
------- | |
add : ndarray | |
Output array of `string_` or `unicode_`, depending on input types | |
of the same shape as `x1` and `x2`. | |
""" | |
arr1 = numpy.asarray(x1) | |
arr2 = numpy.asarray(x2) | |
out_size = _get_num_chars(arr1) + _get_num_chars(arr2) | |
dtype = _use_unicode(arr1, arr2) | |
return _vec_string(arr1, (dtype, out_size), '__add__', (arr2,)) |
Yeah I wasn't intending to post examples of every method on the intro page, just the two to give high level examples of how this module works. I can though also go in and give examples on every page if that would be preferred |
I agree, but to keep the documentation consistent, I suggested it to be in individual pages (essentially functions)
That sounds good! It is also a good idea to have examples in all functions! |
So I thought that there were more pages before I opened this PR (sorry my mistake), but the library isn't 100% consistent about this: |
Agreed. Then the version you have now makes sense as well (do add "more examples are in the functions" sentence as in the link you have shared), but I would still suggest adding the example also in the function which will be more helpful. |
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 @story645 , LGTM! Just one comment about a slight preference for using lists-of-strs for both examples, but not a blocker.
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
@rossbar and @pranaymodukuru should I open an issue about a followup adding examples to the char methods? Also @rossbar do you all do squash merge or is the preference that I rebase? |
I usually squash-merge, so no need to worry about rebasing!
There are already several tracking issues open about docstrings missing examples, e.g. #21351 (comment) (on which |
Not having to track it down myself sounds awesome! 😅 Also thanks for merging! |
Added small examples to String Operations: np.char because honestly I was having trouble parsing the very clear and consistent signatures and had to double check with geeksforgeeks
Um I'm also not actually sure how I can check the docs on .gitpod, tips would be much appreciated.