File tree Expand file tree Collapse file tree 3 files changed +32
-6
lines changed Expand file tree Collapse file tree 3 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -363,13 +363,22 @@ def __getitem__(self, n):
363
363
# Elasticsearch won't get all results so we default to size: 10 if
364
364
# stop not given.
365
365
old_from = s ._extra .get ("from" , 0 )
366
- old_to = old_from + s ._extra .get (
367
- "size" , slice_stop or (slice_start or old_from ) + 10
368
- )
366
+ if "size" in s ._extra :
367
+ old_to = old_from + s ._extra ["size" ]
368
+ elif slice_stop is not None :
369
+ # inherit a size from the given slice
370
+ old_to = old_from + slice_stop
371
+ elif slice_start is not None :
372
+ # assume a default size of 10 from the given slice start
373
+ old_to = old_from + slice_start + 10
374
+ else :
375
+ # with no other information, the default size is 10
376
+ old_to = old_from + 10
369
377
new_from = old_from + (slice_start or 0 )
370
- new_to = (
371
- min (old_to , old_from + slice_stop ) if slice_stop is not None else old_to
372
- )
378
+ if slice_stop is not None :
379
+ new_to = min (old_to , old_from + slice_stop )
380
+ else :
381
+ new_to = old_to
373
382
s ._extra ["from" ] = new_from
374
383
s ._extra ["size" ] = max (0 , new_to - new_from )
375
384
return s
Original file line number Diff line number Diff line change @@ -365,6 +365,13 @@ def test_slice():
365
365
assert {"from" : 10 , "size" : 0 } == s [:5 ][10 :].to_dict ()
366
366
assert {"from" : 12 , "size" : 0 } == s [:5 ][10 :][2 :].to_dict ()
367
367
assert {"from" : 15 , "size" : 0 } == s [10 :][:5 ][5 :].to_dict ()
368
+ assert {"from" : 0 , "size" : 10 } == s [:].to_dict ()
369
+ with raises (ValueError ):
370
+ s [- 1 :]
371
+ with raises (ValueError ):
372
+ s [4 :- 1 ]
373
+ with raises (ValueError ):
374
+ s [- 3 :- 2 ]
368
375
369
376
370
377
def test_index ():
@@ -373,6 +380,8 @@ def test_index():
373
380
assert {"from" : 3 , "size" : 1 } == s [3 ][0 ].to_dict ()
374
381
assert {"from" : 8 , "size" : 0 } == s [3 ][5 ].to_dict ()
375
382
assert {"from" : 4 , "size" : 1 } == s [3 :10 ][1 ].to_dict ()
383
+ with raises (ValueError ):
384
+ s [- 3 ]
376
385
377
386
378
387
def test_search_to_dict ():
Original file line number Diff line number Diff line change @@ -365,6 +365,12 @@ def test_slice():
365
365
assert {"from" : 10 , "size" : 0 } == s [:5 ][10 :].to_dict ()
366
366
assert {"from" : 12 , "size" : 0 } == s [:5 ][10 :][2 :].to_dict ()
367
367
assert {"from" : 15 , "size" : 0 } == s [10 :][:5 ][5 :].to_dict ()
368
+ with raises (ValueError ):
369
+ s [- 1 :]
370
+ with raises (ValueError ):
371
+ s [4 :- 1 ]
372
+ with raises (ValueError ):
373
+ s [- 3 :- 2 ]
368
374
369
375
370
376
def test_index ():
@@ -373,6 +379,8 @@ def test_index():
373
379
assert {"from" : 3 , "size" : 1 } == s [3 ][0 ].to_dict ()
374
380
assert {"from" : 8 , "size" : 0 } == s [3 ][5 ].to_dict ()
375
381
assert {"from" : 4 , "size" : 1 } == s [3 :10 ][1 ].to_dict ()
382
+ with raises (ValueError ):
383
+ s [- 3 ]
376
384
377
385
378
386
def test_search_to_dict ():
You can’t perform that action at this time.
0 commit comments