-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
API: str.cat will align on Series #20347
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
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
97e2996
API: str.cat will align on index (collected)
h-vetinari 84cde8b
Incorporate review feedback
h-vetinari d7587ba
Emit FutureWarning only for different indexes
h-vetinari 7c9735f
Restrict legal argument combinations; no nesting
h-vetinari 1aedf72
Fix edge case for NaN/None; adapted tests; fixes
h-vetinari 2143f19
Revert cat-output-for-cat-caller propsal
h-vetinari fc9aa67
Removed duplicate tests
h-vetinari fcdb57b
Improve tests/errors for str_cat; fix is_legal
h-vetinari 5a237ea
Avoid deep inspection for known types in _get_series_list
h-vetinari 3f77b80
Incorporate review feedback
h-vetinari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Avoid deep inspection for known types in _get_series_list
- Loading branch information
commit 5a237ea61a4d7690966bb5dc8630c18b9fa35542
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1979,8 +1979,8 @@ def _get_series_list(self, others, ignore_index=False): | |
elif isinstance(others, DataFrame): | ||
fut_warn = not others.index.equals(idx) | ||
if ignore_index and fut_warn: | ||
# without copy, this could change (the corresponding list | ||
# element of) "others" that was passed to str.cat | ||
# 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) | ||
|
@@ -1993,22 +1993,27 @@ def _get_series_list(self, others, ignore_index=False): | |
los = [] | ||
fut_warn = False | ||
while others: | ||
nxt = others.pop(0) | ||
# safety for iterators etc.; nxt is list-like as per above | ||
# do not map indexed objects, which would lose their index | ||
if not isinstance(nxt, (DataFrame, Series, Index)): | ||
nxt = others.pop(0) # list-like as per check above | ||
# safety for iterators and other non-persistent list-likes | ||
# do not map indexed/typed objects; would lose information | ||
if not isinstance(nxt, (DataFrame, Series, | ||
Index, np.ndarray)): | ||
nxt = list(nxt) | ||
|
||
# Nested list-likes are forbidden - content of nxt must be | ||
# strings/NaN/None. Need to robustify check against | ||
# x in nxt being list-like (otherwise ambiguous boolean). | ||
is_legal = all((isinstance(x, compat.string_types) | ||
or (not is_list_like(x) and isnull(x)) | ||
or x is None) | ||
for x in nxt) | ||
# known types without deep inspection | ||
no_deep = ((isinstance(nxt, np.ndarray) and nxt.ndim == 1) | ||
or isinstance(nxt, (Series, Index))) | ||
# Nested list-likes are forbidden - elements of nxt must be | ||
# strings/NaN/None. Need to robustify NaN-check against | ||
# x in nxt being list-like (otherwise ambiguous boolean) | ||
is_legal = ((no_deep and nxt.dtype == object) | ||
or all((isinstance(x, compat.string_types) | ||
or (not is_list_like(x) and isnull(x)) | ||
or x is None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isnull already checks for None do this check up front |
||
for x in nxt)) | ||
# DataFrame is false positive of is_legal | ||
# because "x in df" returns column names | ||
if isinstance(nxt, DataFrame) or not is_legal: | ||
if not is_legal or isinstance(nxt, DataFrame): | ||
raise TypeError(err_msg) | ||
|
||
tmp = self._get_series_list(nxt, ignore_index=ignore_index) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this whole section needs some work it’s way too hard to read and follow