Skip to content

Commit 60483ab

Browse files
authored
address issue #52965: add tests
1 parent a505423 commit 60483ab

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

pandas/tests/indexing/test_iloc.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ def test_iloc_getitem_int_and_list_int(self, key, frame_or_series, index, reques
6262
# array of ints (GH5006), make sure that a single indexer is returning
6363
# the correct type
6464

65+
@pytest.mark.parametrize(
66+
"original_type, new_type",
67+
[
68+
(np.uint16, np.uint8),
69+
(np.int32, np.int16),
70+
(np.int64, np.uint64),
71+
(np.int64, np.int16),
72+
],
73+
)
74+
def test_iloc_assign_preserve_dtype(self, original_type, new_type):
75+
s = Series([10, 20, 30], index=list("abc"), dtype=original_type)
76+
s.iloc[0:2] = np.array([100, 200], dtype=new_type)
77+
78+
expected = original_type
79+
assert s.dtype == expected
80+
6581

6682
class TestiLocBaseIndependent:
6783
"""Tests Independent Of Base Class"""

pandas/tests/indexing/test_loc.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,22 @@ def test_loc_empty_slice_assignment_with_datetime(self, data):
277277
df.loc[mask] = df
278278
tm.assert_frame_equal(df, expected)
279279

280+
@pytest.mark.parametrize(
281+
"original_type, new_type",
282+
[
283+
(np.uint16, np.uint8),
284+
(np.int32, np.int16),
285+
(np.int64, np.uint64),
286+
(np.int64, np.int16),
287+
],
288+
)
289+
def test_loc_assign_preserve_dtype(self, original_type, new_type):
290+
s = Series([10, 20, 30], index=list("abc"), dtype=original_type)
291+
s.loc["a":"b"] = np.array([100, 200], dtype=new_type)
292+
293+
expected = original_type
294+
assert s.dtype == expected
295+
280296

281297
class TestLocBaseIndependent:
282298
# Tests for loc that do not depend on subclassing Base

0 commit comments

Comments
 (0)