Skip to content

Commit 88bca04

Browse files
committed
Replaced isinstance check, fixed comments, added asserts in tests
1 parent 083b1ec commit 88bca04

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
@@ -2032,9 +2032,10 @@ def _convert_key(self, key, is_setter: bool = False):
20322032
Require they keys to be the same type as the index. (so we don't
20332033
fallback)
20342034
"""
2035+
# GH 26989
20352036
# For series, unpacking key needs to result in the label.
20362037
# This is already the case for len(key) == 1; e.g. (1,)
2037-
if isinstance(self.obj, ABCSeries) and len(key) > 1:
2038+
if self.ndim == 1 and len(key) > 1:
20382039
key = (key,)
20392040

20402041
# allow arbitrary setting

pandas/tests/indexing/test_scalar.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -355,23 +355,26 @@ def test_iat_series_with_period_index():
355355

356356
def test_tuple_indexed_series_at_get():
357357
# GH 26989
358-
# Series.at works with MultiIndex
358+
# Series.at works with index of tuples
359359
series = Series([1, 2], index=[(1, 2), (3, 4)])
360+
assert series.index.nlevels == 1
360361
assert series.at[1, 2] == 1
361362

362363

363364
def test_tuple_indexed_series_at_set():
364365
# GH 26989
365-
# Series.at works with MultiIndex
366+
# Series.at works with index of tuples
366367
series = Series([1, 2], index=[(1, 2), (3, 4)])
367368
series.at[1, 2] = 3
369+
assert series.index.nlevels == 1
368370
assert series.at[1, 2] == 3
369371

370372

371373
def test_multiindex_series_at_get():
372374
# GH 26989
373375
# Series.at works with MultiIndex
374376
series = Series([1, 2], index=[[1, 2], [3, 4]])
377+
assert series.index.nlevels == 2
375378
assert series.at[1, 3] == 1
376379
assert series.loc[1, 3] == 1
377380

@@ -380,6 +383,7 @@ def test_multiindex_series_at_set():
380383
# GH 26989
381384
# Series.at works with MultiIndex
382385
series = Series([1, 2], index=[[1, 2], [3, 4]])
386+
assert series.index.nlevels == 2
383387
series.at[1, 3] = 3
384388
assert series.at[1, 3] == 3
385389
series.loc[1, 3] = 4

0 commit comments

Comments
 (0)