Skip to content

Commit 0ac84ed

Browse files
committed
Add SortedDict.iloc for improved backwards compatibility with V1
1 parent e434aa3 commit 0ac84ed

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

sortedcontainers/sorteddict.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ def __init__(self, *args, **kwargs):
175175
self.bisect_key = _list.bisect_key
176176
self.irange_key = _list.irange_key
177177

178+
# GrantJ 2018-05-21 Temporary fix for improved backwards compatibility
179+
# with V1.
180+
181+
self.iloc = SortedKeysView(self)
182+
178183
self._update(*args, **kwargs)
179184

180185

tests/test_coverage_sorteddict.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,18 @@ def test_index():
307307
assert temp.index('a') == 0
308308
assert temp.index('f', 3, -3) == 5
309309

310+
def test_iloc():
311+
mapping = [(val, pos) for pos, val in enumerate(string.ascii_lowercase)]
312+
temp = SortedDict(mapping)
313+
assert len(temp.iloc) == 26
314+
assert temp.iloc[0] == 'a'
315+
assert temp.iloc[-1] == 'z'
316+
assert temp.iloc[-3:] == ['x', 'y', 'z']
317+
del temp.iloc[0]
318+
assert temp.iloc[0] == 'b'
319+
del temp.iloc[-3:]
320+
assert temp.iloc[-1] == 'w'
321+
310322
def test_index_key():
311323
temp = SortedDict(negate, ((val, val) for val in range(100)))
312324
temp._reset(7)

0 commit comments

Comments
 (0)