Skip to content

Commit 6d0311d

Browse files
isaac-chungJulianWgs
authored andcommitted
TST: Added iloc tests for casting from object to numeric dtypes for duplicate columns (pandas-dev#41154)
* TST: Added iloc tests for casting from object to numeric dtypes for duplicate columns * Added gh reference * Check df with tm.assert_frame_equal * fix spacing * parametrize over dtypes * pre-commit hooks
1 parent 0aa7598 commit 6d0311d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pandas/tests/indexing/test_iloc.py

+15
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,21 @@ def test_iloc_setitem_series_duplicate_columns(self):
11861186
df.iloc[:, 0] = df.iloc[:, 0].astype(np.float64)
11871187
assert df.dtypes.iloc[2] == np.int64
11881188

1189+
@pytest.mark.parametrize(
1190+
["dtypes", "init_value", "expected_value"],
1191+
[("int64", "0", 0), ("float", "1.2", 1.2)],
1192+
)
1193+
def test_iloc_setitem_dtypes_duplicate_columns(
1194+
self, dtypes, init_value, expected_value
1195+
):
1196+
# GH#22035
1197+
df = DataFrame([[init_value, "str", "str2"]], columns=["a", "b", "b"])
1198+
df.iloc[:, 0] = df.iloc[:, 0].astype(dtypes)
1199+
expected_df = DataFrame(
1200+
[[expected_value, "str", "str2"]], columns=["a", "b", "b"]
1201+
)
1202+
tm.assert_frame_equal(df, expected_df)
1203+
11891204

11901205
class TestILocCallable:
11911206
def test_frame_iloc_getitem_callable(self):

0 commit comments

Comments
 (0)