Skip to content

Commit 258adc4

Browse files
committed
Replaced isinstance check, fixed comments, added asserts in tests
1 parent f7b2395 commit 258adc4

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
@@ -2060,9 +2060,10 @@ def _convert_key(self, key, is_setter: bool = False):
20602060
Require they keys to be the same type as the index. (so we don't
20612061
fallback)
20622062
"""
2063+
# GH 26989
20632064
# For series, unpacking key needs to result in the label.
20642065
# This is already the case for len(key) == 1; e.g. (1,)
2065-
if isinstance(self.obj, ABCSeries) and len(key) > 1:
2066+
if self.ndim == 1 and len(key) > 1:
20662067
key = (key,)
20672068

20682069
# allow arbitrary setting

pandas/tests/indexing/test_scalar.py

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

316316
def test_tuple_indexed_series_at_get():
317317
# GH 26989
318-
# Series.at works with MultiIndex
318+
# Series.at works with index of tuples
319319
series = Series([1, 2], index=[(1, 2), (3, 4)])
320+
assert series.index.nlevels == 1
320321
assert series.at[1, 2] == 1
321322

322323

323324
def test_tuple_indexed_series_at_set():
324325
# GH 26989
325-
# Series.at works with MultiIndex
326+
# Series.at works with index of tuples
326327
series = Series([1, 2], index=[(1, 2), (3, 4)])
327328
series.at[1, 2] = 3
329+
assert series.index.nlevels == 1
328330
assert series.at[1, 2] == 3
329331

330332

331333
def test_multiindex_series_at_get():
332334
# GH 26989
333335
# Series.at works with MultiIndex
334336
series = Series([1, 2], index=[[1, 2], [3, 4]])
337+
assert series.index.nlevels == 2
335338
assert series.at[1, 3] == 1
336339
assert series.loc[1, 3] == 1
337340

@@ -340,6 +343,7 @@ def test_multiindex_series_at_set():
340343
# GH 26989
341344
# Series.at works with MultiIndex
342345
series = Series([1, 2], index=[[1, 2], [3, 4]])
346+
assert series.index.nlevels == 2
343347
series.at[1, 3] = 3
344348
assert series.at[1, 3] == 3
345349
series.loc[1, 3] = 4

0 commit comments

Comments
 (0)