Skip to content

Commit e0a29ca

Browse files
committed
TST: Test Series' settitem with Interval and NaN
Fixes #27937. As described in that issue, assigning a mixture of NaN and Interval values into a slice of a categorical-typed series would raise an exception. This is no longer the case.
1 parent 62d1f5c commit e0a29ca

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pandas/tests/indexing/test_iloc.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,16 @@ def test_iloc_setitem_td64_values_cast_na(self, value):
931931
expected = Series([NaT, 1, 2], dtype="timedelta64[ns]")
932932
tm.assert_series_equal(series, expected)
933933

934+
@pytest.mark.parametrize("not_na", [Interval(0, 1), 'a', 1.0])
935+
@pytest.mark.parametrize("na", [np.nan, NaT])
936+
def test_setitem_mix_of_nan_and_interval(self, not_na, na):
937+
# GH#27937
938+
dtype = CategoricalDtype(categories=[not_na])
939+
ser = Series([na, na, na, na], dtype=dtype)
940+
ser.iloc[:3] = [na, not_na, na]
941+
exp = Series([na, not_na, na, na], dtype=dtype)
942+
tm.assert_series_equal(ser, exp)
943+
934944
def test_iloc_setitem_empty_frame_raises_with_3d_ndarray(self):
935945
idx = Index([])
936946
obj = DataFrame(np.random.randn(len(idx), len(idx)), index=idx, columns=idx)

0 commit comments

Comments
 (0)