Skip to content

Commit 46025b0

Browse files
committed
Fixed issues from review
Added whatsnew to 0.24 Added issue to tests comments Moved some test Added a test from the issue
1 parent f47ba8e commit 46025b0

File tree

3 files changed

+52
-21
lines changed

3 files changed

+52
-21
lines changed

doc/source/whatsnew/v0.24.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ Indexing
656656
- Fixed ``DataFrame[np.nan]`` when columns are non-unique (:issue:`21428`)
657657
- Bug when indexing :class:`DatetimeIndex` with nanosecond resolution dates and timezones (:issue:`11679`)
658658
- Bug where indexing with a Numpy array containing negative values would mutate the indexer (:issue:`21867`)
659+
- Bug where mixed indexes wouldn't allow integers for ``.at`` (:issue:`19860`)
659660

660661
Missing
661662
^^^^^^^

pandas/tests/indexing/test_indexing.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,22 @@ def test_index_contains(self, index, val):
610610
def test_index_not_contains(self, index, val):
611611
assert val not in index
612612

613+
@pytest.mark.parametrize("index,val", [
614+
(Index([0, 1, '2']), 0),
615+
(Index([0, 1, '2']), '2'),
616+
])
617+
def test_mixed_index_contains(self, index, val):
618+
# GH 19860
619+
assert val in index
620+
621+
@pytest.mark.parametrize("index,val", [
622+
(Index([0, 1, '2']), '1'),
623+
(Index([0, 1, '2']), 2),
624+
])
625+
def test_mixed_index_not_contains(self, index, val):
626+
# GH 19860
627+
assert val not in index
628+
613629
def test_index_type_coercion(self):
614630

615631
with catch_warnings(record=True):
@@ -666,20 +682,6 @@ def test_index_type_coercion(self):
666682
idxr(s2)['0'] = 0
667683
assert s2.index.is_object()
668684

669-
@pytest.mark.parametrize("index,val", [
670-
(Index([0, 1, '2']), '1'),
671-
(Index([0, 1, '2']), 2),
672-
])
673-
def test_mixed_index_not_contains(self, index, val):
674-
assert val not in index
675-
676-
@pytest.mark.parametrize("index,val", [
677-
(Index([0, 1, '2']), 0),
678-
(Index([0, 1, '2']), '2'),
679-
])
680-
def test_mixed_index_contains(self, index, val):
681-
assert val in index
682-
683685

684686
class TestMisc(Base):
685687

@@ -724,21 +726,16 @@ def test_float_index_at_iat(self):
724726
for i in range(len(s)):
725727
assert s.iat[i] == i + 1
726728

727-
def test_mixed_index_at_iat(self):
728-
s = Series([1, 2, 3, 4, 5], index=['a', 'b', 'c', 1, 2])
729-
for el, item in s.iteritems():
730-
assert s.at[el] == item
731-
for i in range(len(s)):
732-
assert s.iat[i] == i + 1
733-
734729
def test_mixed_index_assignment(self):
730+
# GH 19860
735731
s = Series([1, 2, 3, 4, 5], index=['a', 'b', 'c', 1, 2])
736732
s.at['a'] = 11
737733
assert s.iat[0] == 11
738734
s.at[1] = 22
739735
assert s.iat[3] == 22
740736

741737
def test_mixed_index_no_fallback(self):
738+
# GH 19860
742739
s = Series([1, 2, 3, 4, 5], index=['a', 'b', 'c', 1, 2])
743740
with pytest.raises(KeyError):
744741
s.at[0]

pandas/tests/indexing/test_scalar.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,36 @@ def test_at_with_tz(self):
170170

171171
result = df.at[0, 'date']
172172
assert result == expected
173+
174+
def test_mixed_index_at_iat_loc_iloc_series(self):
175+
# GH 19860
176+
s = Series([1, 2, 3, 4, 5], index=['a', 'b', 'c', 1, 2])
177+
for el, item in s.iteritems():
178+
assert s.at[el] == s.loc[el] == item
179+
for i in range(len(s)):
180+
assert s.iat[i] == s.iloc[i] == i + 1
181+
182+
with pytest.raises(KeyError):
183+
s.at[4]
184+
with pytest.raises(KeyError):
185+
s.loc[4]
186+
187+
188+
def test_mixed_index_at_iat_loc_iloc_dataframe(self):
189+
# GH 19860
190+
df = DataFrame([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]],
191+
columns=['a', 'b', 'c', 1, 2])
192+
for rowIdx, row in df.iterrows():
193+
for el, item in row.iteritems():
194+
assert df.at[rowIdx, el] == df.loc[rowIdx, el] == item
195+
196+
for row in range(2):
197+
for i in range(5):
198+
assert df.iat[row, i] == df.iloc[row, i] == row * 5 + i
199+
200+
with pytest.raises(KeyError):
201+
df.at[0, 3]
202+
with pytest.raises(KeyError):
203+
df.loc[0, 3]
204+
205+

0 commit comments

Comments
 (0)