8000 DOC: Add examples to ``np.char`` by luxedo · Pull Request #26642 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

DOC: Add examples to np.char #26642

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 13 commits into from
Oct 14, 2024
9 changes: 9 additions & 0 deletions numpy/_core/code_generators/ufunc_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4560,6 +4560,15 @@ def add_newdoc(place, name, doc):
--------
str.isspace

Examples
--------
>>> np.char.isspace(list("a b c"))
array([False, True, False, True, False])
>>> np.char.isspace(b'\x0a \x0b \x0c')
np.True_
>>> np.char.isspace(b'\x0a \x0b \x0c N')
np.False_

""")

add_newdoc('numpy._core.umath', 'isalnum',
Expand Down
10 changes: 10 additions & 0 deletions numpy/_core/defchararray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,16 @@ class adds the following functionality:
fastest). If order is 'A', then the returned array may
be in any order (either C-, Fortran-contiguous, or even
discontiguous).

Examples
--------
>>> np.char.array(["a", "b", "c"])
chararray(['a', 'b', 'c'], dtype='<U1')
>>> np.char.array(["a", "b", "c"], itemsize=8)
chararray(['a', 'b', 'c'], dtype='<U8')
>>> np.char.array([1, 2, 3])
chararray([b'1', b'2', b'3'], dtype='|S1')

"""
if isinstance(obj, (bytes, str)):
if unicode is None:
Expand Down
8 changes: 8 additions & 0 deletions numpy/_core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,14 @@ def _splitlines(a, keepends=None):
--------
str.splitlines

Examples
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless there's some magic that uses the docstring of the private function in the public function, not sure if this is needed here?

--------
>>> np.char.splitlines("first line\\nsecond line")
array(list(['first line', 'second line']), dtype=object)
>>> a = np.array(["first\\nsecond", "third\\nfourth"])
>>> np.char.splitlines(a)
array([list(['first', 'second']), list(['third', 'fourth'])], dtype=object)

"""
return _vec_string(
a, np.object_, 'splitlines', _clean_args(keepends))
Expand Down
0