Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pandas/tests/indexing/test_iloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ def test_iloc_getitem_int_and_list_int(self, key, frame_or_series, index, reques
# array of ints (GH5006), make sure that a single indexer is returning
# the correct type

@pytest.mark.parametrize(
"original_type, new_type",
[
(np.uint16, np.uint8),
(np.int32, np.int16),
(np.int64, np.uint64),
(np.int64, np.int16),
],
)
def test_iloc_assign_preserve_dtype(self, original_type, new_type):
s = Series([10, 20, 30], index=list("abc"), dtype=original_type)
s.iloc[0:2] = np.array([100, 200], dtype=new_type)

expected = original_type
assert s.dtype == expected


class TestiLocBaseIndependent:
"""Tests Independent Of Base Class"""
Expand Down
16 changes: 16 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,22 @@ def test_loc_empty_slice_assignment_with_datetime(self, data):
df.loc[mask] = df
tm.assert_frame_equal(df, expected)

@pytest.mark.parametrize(
"original_type, new_type",
[
(np.uint16, np.uint8),
(np.int32, np.int16),
(np.int64, np.uint64),
(np.int64, np.int16),
],
)
def test_loc_assign_preserve_dtype(self, original_type, new_type):
s = Series([10, 20, 30], index=list("abc"), dtype=original_type)
s.loc["a":"b"] = np.array([100, 200], dtype=new_type)

expected = original_type
assert s.dtype == expected


class TestLocBaseIndependent:
# Tests for loc that do not depend on subclassing Base
Expand Down
Loading