REGR: using loc to add rows doesn't preserve dtypes #3125
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.
Potential ideas for solving this. As implemented,
_constructor_from_mgr
stays nice and clean, but relies too heavily on the pandas internals for my liking (though in an ideal world pandas would expose some way to handle less straightforward dtype concatenation cases).Edit: This kind of approach is not going to work because of this if else in compat compat:
https://github.com/pandas-dev/pandas/blob/612823e824805b97a2dbe258ba808dc572083d49/pandas/core/dtypes/concat.py#L128-L144
This block assumes
to_concat
shares a common dtype, and with this trick that's not trueI expect we'll end up using something along the lines of the update to
_constructor_from_mgr
which is commented out at the moment.