8000 DOC: added example in char by story645 · Pull Request #22500 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 2 commits into from
Oct 31, 2022
Merged

DOC: added example in char #22500

merged 2 commits into from
Oct 31, 2022

Conversation

story645
Copy link
Contributor

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.

>>> 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`
Copy link
Contributor Author

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`

Copy link
@pranaymodukuru pranaymodukuru left a 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.

Copy link
@pranaymodukuru pranaymodukuru left a 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

@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,))

@story645
Copy link
Contributor Author
story645 commented Oct 31, 2022

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

@pranaymodukuru
Copy link

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 agree, but to keep the documentation consistent, I suggested it to be in individual pages (essentially functions)

I can though also go in and give examples on every page if that would be preferred

That sounds good! It is also a good idea to have examples in all functions!

@story645
Copy link
Contributor Author

I agree, but to keep the documentation consistent, I suggested it to be in individual pages (essentially 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:

@pranaymodukuru
Copy link
pranaymodukuru commented Oct 31, 2022

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.

Copy link
Contributor
@rossbar rossbar left a 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>
@story645
Copy link
Contributor Author
story645 commented Oct 31, 2022

@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?

@rossbar
Copy link
Contributor
rossbar commented Oct 31, 2022

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!

should I open an issue about a followup adding examples to the char methods?

There are already several tracking issues open about docstrings missing examples, e.g. #21351 (comment) (on which np.char features prominently). If you're interested in working on these and another issue would be useful to you to track work, then go ahead and open a new one! Otherwise we can stick with maybe updating/closing down some of the existing doc issues about missing examples.

@rossbar rossbar merged commit f569129 into numpy:main Oct 31, 2022
@story645
Copy link
Contributor Author
story645 commented Oct 31, 2022

Not having to track it down myself sounds awesome! 😅

Also thanks for merging!

@story645 story645 deleted the strdoc branch November 1, 2022 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0