Skip to content

Commit bee54e7

Browse files
committed
Replaced isinstance check, fixed comments, added asserts in tests
1 parent 3f8d6b8 commit bee54e7

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

pandas/core/indexing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2057,9 +2057,10 @@ def _convert_key(self, key, is_setter: bool = False):
20572057
Require they keys to be the same type as the index. (so we don't
20582058
fallback)
20592059
"""
2060+
# GH 26989
20602061
# For series, unpacking key needs to result in the label.
20612062
# This is already the case for len(key) == 1; e.g. (1,)
2062-
if isinstance(self.obj, ABCSeries) and len(key) > 1:
2063+
if self.ndim == 1 and len(key) > 1:
20632064
key = (key,)
20642065

20652066
# allow arbitrary setting

pandas/tests/indexing/test_scalar.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -306,23 +306,26 @@ def test_iat_dont_wrap_object_datetimelike():
306306

307307
def test_tuple_indexed_series_at_get():
308308
# GH 26989
309-
# Series.at works with MultiIndex
309+
# Series.at works with index of tuples
310310
series = Series([1, 2], index=[(1, 2), (3, 4)])
311+
assert series.index.nlevels == 1
311312
assert series.at[1, 2] == 1
312313

313314

314315
def test_tuple_indexed_series_at_set():
315316
# GH 26989
316-
# Series.at works with MultiIndex
317+
# Series.at works with index of tuples
317318
series = Series([1, 2], index=[(1, 2), (3, 4)])
318319
series.at[1, 2] = 3
320+
assert series.index.nlevels == 1
319321
assert series.at[1, 2] == 3
320322

321323

322324
def test_multiindex_series_at_get():
323325
# GH 26989
324326
# Series.at works with MultiIndex
325327
series = Series([1, 2], index=[[1, 2], [3, 4]])
328+
assert series.index.nlevels == 2
326329
assert series.at[1, 3] == 1
327330
assert series.loc[1, 3] == 1
328331

@@ -331,6 +334,7 @@ def test_multiindex_series_at_set():
331334
# GH 26989
332335
# Series.at works with MultiIndex
333336
series = Series([1, 2], index=[[1, 2], [3, 4]])
337+
assert series.index.nlevels == 2
334338
series.at[1, 3] = 3
335339
assert series.at[1, 3] == 3
336340
series.loc[1, 3] = 4

0 commit comments

Comments
 (0)