Skip to content

DOC: Updated docstring for Series.str.cat (pandas-dev#35556) #35784

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

Closed
wants to merge 17 commits into from
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2371,8 +2371,7 @@ def cat(self, others=None, sep=None, na_rep=None, join="left"):
join : {'left', 'right', 'outer', 'inner'}, default 'left'
Determines the join-style between the calling Series/Index and any
Series/Index/DataFrame in `others` (objects without an index need
to match the length of the calling Series/Index). To disable
alignment, use `.values` on any Series/Index/DataFrame in `others`.
to match the length of the calling Series/Index).

.. versionadded:: 0.23.0
.. versionchanged:: 1.0.0
Expand All @@ -2389,6 +2388,15 @@ def cat(self, others=None, sep=None, na_rep=None, join="left"):
split : Split each string in the Series/Index.
join : Join lists contained as elements in the Series/Index.

Notes
-----
Since version 1.0.0, index alignment is performed when
`others` is a Series/Index/DataFrame (or a list-like containing
Copy link
Member

Choose a reason for hiding this comment

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

is this true for an Index? If the behavior is anything like arithmetic, we would do alignment for Series/DataFrame, but Index would behave more like ndarray

one). To disable alignment (the behavior in and before v0.23.0),
convert `others` to a numpy array while passing it as an argument
(using `.to_numpy()`). See the Examples section below for more
information.

Examples
--------
When not passing `others`, all values are concatenated into a single
Expand Down Expand Up @@ -2466,7 +2474,27 @@ def cat(self, others=None, sep=None, na_rep=None, join="left"):
2 -c
dtype: object

For more examples, see :ref:`here <text.concatenate>`.
When `others` is a Series/Index/DataFrame, it is advisable
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to explain why one should do this. e.g. to have alignment since the join is defaulting to left.

show an example first with index and index, then index and series of the index and it should be more clear.

to use `to_numpy()` while passing it to the function to
avoid unexpected results.
Copy link
Contributor

Choose a reason for hiding this comment

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

remove the 'unexpected results'.


The following example demostrates this:
Copy link
Member

Choose a reason for hiding this comment

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

this and the next paragraph both end in colons. is this paragraph needed?


If `others` is a Series/Index/DataFrame and `to_numpy()`
**is not** used:

>>> idx = pd.Index(["a", "b", "c", "d", "e"])
>>> ser = pd.Series(["f", "g", "h", "i", "j"])
>>> idx.str.cat(ser) # the caller is an Index here
Copy link
Member

Choose a reason for hiding this comment

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

one more space before the #

Index([nan, nan, nan, nan, nan], dtype='object')

When `to_numpy()` **is** used:

>>> idx.str.cat(ser.to_numpy())
Index(['af', 'bg', 'ch', 'di', 'ej'], dtype='object')

For other examples and usages, see
:ref:`here <text.concatenate>`.
"""
from pandas import Index, Series, concat

Expand Down