-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
BUG: concat losing columns dtypes for join=outer #47586
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
3 commits
Select commit
Hold shift + click to select a range
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
Next
Next commit
BUG: concat losing columns dtypes for join=outer
- Loading branch information
commit 75d4fda70f9c47ce7e07a75dc7cb424b51e8ffb1
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 |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| ) | ||
| from pandas.errors import InvalidIndexError | ||
|
|
||
| from pandas.core.dtypes.cast import find_common_type | ||
| from pandas.core.dtypes.common import is_dtype_equal | ||
|
|
||
| from pandas.core.algorithms import safe_sort | ||
|
|
@@ -223,7 +224,7 @@ def union_indexes(indexes, sort: bool | None = True) -> Index: | |
|
|
||
| indexes, kind = _sanitize_and_check(indexes) | ||
|
|
||
| def _unique_indices(inds) -> Index: | ||
| def _unique_indices(inds, dtype) -> Index: | ||
|
Member
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. the docstring also needs updating at some point. |
||
| """ | ||
| Convert indexes to lists and concatenate them, removing duplicates. | ||
|
|
||
|
|
@@ -243,7 +244,10 @@ def conv(i): | |
| i = i.tolist() | ||
| return i | ||
|
|
||
| return Index(lib.fast_unique_multiple_list([conv(i) for i in inds], sort=sort)) | ||
| return Index( | ||
| lib.fast_unique_multiple_list([conv(i) for i in inds], sort=sort), | ||
| dtype=dtype, | ||
| ) | ||
|
|
||
| if kind == "special": | ||
| result = indexes[0] | ||
|
|
@@ -283,16 +287,22 @@ def conv(i): | |
| return result | ||
|
|
||
| elif kind == "array": | ||
| dtype = find_common_type( | ||
| [idx.dtype for idx in indexes if isinstance(idx, Index)] | ||
| ) | ||
| index = indexes[0] | ||
| if not all(index.equals(other) for other in indexes[1:]): | ||
| index = _unique_indices(indexes) | ||
| index = _unique_indices(indexes, dtype) | ||
|
|
||
| name = get_unanimous_names(*indexes)[0] | ||
| if name != index.name: | ||
| index = index.rename(name) | ||
| return index | ||
| else: # kind='list' | ||
| return _unique_indices(indexes) | ||
| dtype = find_common_type( | ||
| [idx.dtype for idx in indexes if isinstance(idx, Index)] | ||
| ) | ||
| return _unique_indices(indexes, dtype) | ||
|
|
||
|
|
||
| def _sanitize_and_check(indexes): | ||
|
|
||
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.
issue is marked as 1.4.4. ok to leave in 1.5 though (if so just change the issue and ignore this comment)
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.
Changed the milestones.
initially we though this happens only
for ea dtypes, but this was wrong. Occurs also for numpy dtypes