-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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 all commits
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
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1149,6 +1149,23 @@ def test_loc_setitem_listlike_with_timedelta64index(self, indexer, expected): | |
|
||
tm.assert_frame_equal(expected, df) | ||
|
||
def test_loc_setitem_null_slice_single_column_series_value_different_dtype(self): | ||
# GH#20635 | ||
df = DataFrame({"A": ["a", "b"], "B": ["1", "2"], "C": ["3", "4"]}) | ||
df.loc[:, "C"] = df["C"].astype("int64") | ||
expected = DataFrame({"A": ["a", "b"], "B": ["1", "2"], "C": [3, 4]}) | ||
tm.assert_frame_equal(df, expected) | ||
|
||
@pytest.mark.parametrize("dtype", ["int64", "Int64"]) | ||
def test_loc_setitem_null_slice_different_dtypes(self, dtype): | ||
# GH#20635 | ||
df = DataFrame({"A": ["a", "b"], "B": ["1", "2"], "C": ["3", "4"], "D": [1, 2]}) | ||
rhs = df[["B", "C"]].astype("int64").astype(dtype) | ||
df.loc[:, ["B", "C"]] = rhs | ||
expected = DataFrame({"A": ["a", "b"], "B": [1, 2], "C": [3, 4], "D": [1, 2]}) | ||
expected[["B", "C"]] = expected[["B", "C"]].astype(dtype) | ||
tm.assert_frame_equal(df, expected) | ||
|
||
|
||
class TestLocWithMultiIndex: | ||
@pytest.mark.parametrize( | ||
|
@@ -2117,6 +2134,14 @@ def test_loc_setitem_dt64tz_values(self): | |
result = s2["a"] | ||
assert result == expected | ||
|
||
@pytest.mark.parametrize("dtype", ["int64", "Int64"]) | ||
def test_loc_setitem_series_null_slice_different_dtypes(self, dtype): | ||
# GH#20635 | ||
ser = Series(["3", "4"], name="A") | ||
ser.loc[:] = ser.astype("int64").astype(dtype) | ||
expected = Series([3, 4], name="A", dtype=dtype) | ||
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. i think this is doing the opposite of #39163. did we decide to revert part or all of that? 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. Since yours is significantly newer I am fine with „closing“ this. Would check if some of the issues are fixed |
||
tm.assert_series_equal(ser, expected) | ||
|
||
@pytest.mark.parametrize("array_fn", [np.array, pd.array, list, tuple]) | ||
@pytest.mark.parametrize("size", [0, 4, 5, 6]) | ||
def test_loc_iloc_setitem_with_listlike(self, size, array_fn): | ||
|
Uh oh!
There was an error while loading. Please reload this page.