Skip to content

Commit

Permalink
Incorporate review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari committed May 2, 2018
1 parent 58a8e42 commit 1c06234
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions doc/source/text.rst
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ Concatenating a Series and an indexed object into a Series, with alignment

.. versionadded:: 0.23.0

For concatenation with a ``Series`` or ``DataFrame``, it is possible to align the respective indexes before concatenation by setting
the ``join``-keyword, which controls the manner of alignment.
For concatenation with a ``Series`` or ``DataFrame``, it is possible to align the indexes before concatenation by setting
the ``join``-keyword.

.. ipython:: python
Expand All @@ -282,7 +282,7 @@ the ``join``-keyword, which controls the manner of alignment.
If the ``join`` keyword is not passed, the method :meth:`~Series.str.cat` will currently fall back to the behavior before version 0.23.0 (i.e. no alignment),
but a ``FutureWarning`` will be raised if any of the involved indexes differ, since this default will change to ``join='left'`` in a future version.

To usual options are available for ``join`` (one of ``'left', 'outer', 'inner', 'right'``).
The usual options are available for ``join`` (one of ``'left', 'outer', 'inner', 'right'``).
In particular, alignment also means that the different lengths do not need to coincide anymore.

.. ipython:: python
Expand Down
35 changes: 18 additions & 17 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1964,34 +1964,34 @@ def _get_series_list(self, others, ignore_index=False):

err_msg = ('others must be Series, Index, DataFrame, np.ndarrary or '
'list-like (either containing only strings or containing '
'only objects of type Series/Index/list-like/np.ndarray')
'only objects of type Series/Index/list-like/np.ndarray)')

if isinstance(others, Series):
fut_warn = not others.index.equals(idx)
fu_wrn = not others.index.equals(idx)
los = [Series(others.values, index=idx)
if ignore_index and fut_warn else others]
return (los, fut_warn)
if ignore_index and fu_wrn else others]
return (los, fu_wrn)
elif isinstance(others, Index):
fut_warn = not others.equals(idx)
fu_wrn = not others.equals(idx)
los = [Series(others.values,
index=(idx if ignore_index else others))]
return (los, fut_warn)
return (los, fu_wrn)
elif isinstance(others, DataFrame):
fut_warn = not others.index.equals(idx)
if ignore_index and fut_warn:
fu_wrn = not others.index.equals(idx)
if ignore_index and fu_wrn:
# without copy, this could change "others"
# that was passed to str.cat
others = others.copy()
others.index = idx
return ([others[x] for x in others], fut_warn)
return ([others[x] for x in others], fu_wrn)
elif isinstance(others, np.ndarray) and others.ndim == 2:
others = DataFrame(others, index=idx)
return ([others[x] for x in others], False)
elif is_list_like(others):
others = list(others) # ensure iterators do not get read twice etc
if all(is_list_like(x) for x in others):
los = []
fut_warn = False
fu_wrn = False
while others:
nxt = others.pop(0) # list-like as per check above
# safety for iterators and other non-persistent list-likes
Expand All @@ -2016,10 +2016,11 @@ def _get_series_list(self, others, ignore_index=False):
if not is_legal or isinstance(nxt, DataFrame):
raise TypeError(err_msg)

tmp = self._get_series_list(nxt, ignore_index=ignore_index)
los = los + tmp[0]
fut_warn = fut_warn or tmp[1]
return (los, fut_warn)
nxt, fwn = self._get_series_list(nxt,
ignore_index=ignore_index)
los = los + nxt
fu_wrn = fu_wrn or fwn
return (los, fu_wrn)
# test if there is a mix of list-like and non-list-like (e.g. str)
elif (any(is_list_like(x) for x in others)
and any(not is_list_like(x) for x in others)):
Expand Down Expand Up @@ -2186,8 +2187,8 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):

try:
# turn anything in "others" into lists of Series
tmp = self._get_series_list(others, ignore_index=(join is None))
others, fut_warn = tmp
others, fu_wrn = self._get_series_list(others,
ignore_index=(join is None))
except ValueError: # do not catch TypeError raised by _get_series_list
if join is None:
raise ValueError('All arrays must be same length, except '
Expand All @@ -2198,7 +2199,7 @@ def cat(self, others=None, sep=None, na_rep=None, join=None):
'must all be of the same length as the '
'calling Series/Index.')

if join is None and fut_warn:
if join is None and fu_wrn:
warnings.warn("A future version of pandas will perform index "
"alignment when `others` is a Series/Index/"
"DataFrame (or a list-like containing one). To "
Expand Down

0 comments on commit 1c06234

Please sign in to comment.