-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
BUG: Bug in loc did not change dtype when complete column was assigned #37749
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
Changes from 1 commit
6450a2c
1599c5c
4d39612
f9f37cb
5cf355b
8d203f9
e35e009
4c391da
71fbf9f
babcd38
caa6046
8b95236
3b98ee0
f9b8a59
4bef38e
27ea3e2
f94277b
279e812
d5f6150
706dc6a
66d4b4e
fa25075
3c06ba6
a33659c
0f556c4
181e62a
b759ac9
a353930
d28e1e1
1aa8522
1bc0d46
61aab16
14fe5a8
26b5d6f
913ffea
e6e22f3
23f6f3b
99b87c9
f97a252
700ce6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| is_object_dtype, | ||
| is_scalar, | ||
| is_sequence, | ||
| is_dtype_equal, | ||
| ) | ||
| from pandas.core.dtypes.concat import concat_compat | ||
| from pandas.core.dtypes.generic import ABCDataFrame, ABCMultiIndex, ABCSeries | ||
|
|
@@ -1550,6 +1551,11 @@ def _setitem_with_indexer(self, indexer, value): | |
| val = list(value.values()) if isinstance(value, dict) else value | ||
| blk = self.obj._mgr.blocks[0] | ||
| take_split_path = not blk._can_hold_element(val) | ||
|
||
| if isinstance(value, ABCDataFrame): | ||
| dtypes = [dtype for dtype in value.dtypes.unique()] | ||
| take_split_path = not ( | ||
| len(dtypes) == 1 and is_dtype_equal(dtypes[0], blk.dtype) | ||
| ) | ||
|
|
||
| # if we have any multi-indexes that have non-trivial slices | ||
| # (not null slices) then we must take the split path, xref | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -298,6 +298,13 @@ def test_iloc_setitem_bool_indexer(self, klass): | |
| expected = DataFrame({"flag": ["x", "y", "z"], "value": [2, 3, 4]}) | ||
| tm.assert_frame_equal(df, expected) | ||
|
|
||
| def test_setitem_complete_columns_different_dtypes(self): | ||
|
||
| # GH: 20635 | ||
| df = DataFrame({"A": ["a", "b"], "B": ["1", "2"], "C": ["3", "4"]}) | ||
| df.loc[:, ["B", "C"]] = df.loc[:, ["B", "C"]].astype("int") | ||
| expected = DataFrame({"A": ["a", "b"], "B": [1, 2], "C": [3, 4]}) | ||
| tm.assert_frame_equal(df, expected) | ||
|
|
||
|
|
||
| class TestDataFrameSetItemSlicing: | ||
| def test_setitem_slice_position(self): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.