-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Fixed concat with reindex and extension types #33522
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 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bd316c3
BUG: Fixed concat with reindex and extension types
TomAugspurger 87a1d31
Merge remote-tracking branch 'upstream/master' into concat-empty-ea
TomAugspurger 7fc30a0
rebase
TomAugspurger 709ac02
Merge remote-tracking branch 'upstream/master' into concat-empty-ea
TomAugspurger 93f0069
Merge remote-tracking branch 'upstream/master' into concat-empty-ea
TomAugspurger 187551c
fixup
TomAugspurger a83a5fe
cleanup
TomAugspurger 2c2b9b5
Merge remote-tracking branch 'upstream/master' into concat-empty-ea
TomAugspurger 13c1fe7
fixups
TomAugspurger 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
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 |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
|
||
|
||
def concatenate_block_managers( | ||
mgrs_indexers, axes, concat_axis: int, copy: bool | ||
mgrs_indexers, axes, concat_axis: int, copy: bool, | ||
) -> BlockManager: | ||
""" | ||
Concatenate block managers into one. | ||
|
@@ -76,7 +76,7 @@ def concatenate_block_managers( | |
b = make_block(values, placement=placement, ndim=blk.ndim) | ||
else: | ||
b = make_block( | ||
_concatenate_join_units(join_units, concat_axis, copy=copy), | ||
_concatenate_join_units(join_units, concat_axis, copy=copy,), | ||
placement=placement, | ||
) | ||
blocks.append(b) | ||
|
@@ -260,6 +260,16 @@ def get_reindexed_values(self, empty_dtype, upcasted_na): | |
pass | ||
elif getattr(self.block, "is_extension", False): | ||
pass | ||
elif is_extension_array_dtype(empty_dtype): | ||
missing_arr = empty_dtype.construct_array_type()._from_sequence( | ||
[], dtype=empty_dtype | ||
) | ||
ncols, nrows = self.shape | ||
assert ncols == 1, ncols | ||
empty_arr = -1 * np.ones((nrows,), dtype="int8") | ||
return missing_arr.take( | ||
empty_arr, allow_fill=True, fill_value=fill_value | ||
) | ||
else: | ||
missing_arr = np.empty(self.shape, dtype=empty_dtype) | ||
missing_arr.fill(fill_value) | ||
|
@@ -329,7 +339,7 @@ def _concatenate_join_units(join_units, concat_axis, copy): | |
# 2D to put it a non-EA Block | ||
concat_values = np.atleast_2d(concat_values) | ||
else: | ||
concat_values = concat_compat(to_concat, axis=concat_axis) | ||
concat_values = concat_compat(to_concat, axis=concat_axis,) | ||
|
||
return concat_values | ||
|
||
|
@@ -374,6 +384,10 @@ def _get_empty_dtype_and_na(join_units): | |
upcast_cls = "category" | ||
elif is_datetime64tz_dtype(dtype): | ||
upcast_cls = "datetimetz" | ||
|
||
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. sort of dumb, but no blank lines before/after |
||
elif is_extension_array_dtype(dtype): | ||
upcast_cls = "extension" | ||
|
||
elif issubclass(dtype.type, np.bool_): | ||
upcast_cls = "bool" | ||
elif issubclass(dtype.type, np.object_): | ||
|
@@ -384,8 +398,6 @@ def _get_empty_dtype_and_na(join_units): | |
upcast_cls = "timedelta" | ||
elif is_sparse(dtype): | ||
upcast_cls = dtype.subtype.name | ||
elif is_extension_array_dtype(dtype): | ||
upcast_cls = "object" | ||
elif is_float_dtype(dtype) or is_numeric_dtype(dtype): | ||
upcast_cls = dtype.name | ||
else: | ||
|
@@ -401,6 +413,12 @@ def _get_empty_dtype_and_na(join_units): | |
|
||
if not upcast_classes: | ||
upcast_classes = null_upcast_classes | ||
if "extension" in upcast_classes: | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if len(upcast_classes) == 1: | ||
cls = upcast_classes["extension"][0] | ||
return cls, cls.na_value | ||
else: | ||
return np.dtype("object"), np.nan | ||
|
||
# TODO: de-duplicate with maybe_promote? | ||
# create the result | ||
|
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
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 |
---|---|---|
|
@@ -93,7 +93,8 @@ class TestConstructors(base.BaseConstructorsTests): | |
|
||
|
||
class TestReshaping(base.BaseReshapingTests): | ||
pass | ||
def test_concat_with_reindex(self, data): | ||
pytest.xfail(reason="Deliberately upcast to object?") | ||
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. Do we have an issue for this? (it seems we shouldn't cast to object when only needing to append NaNs?) |
||
|
||
|
||
class TestGetitem(base.BaseGetitemTests): | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.