File tree 2 files changed +16
-10
lines changed
2 files changed +16
-10
lines changed Original file line number Diff line number Diff line change 3
3
import warnings
4
4
import operator
5
5
from functools import partial
6
- from math import ceil , floor
7
-
8
6
from sys import getsizeof
9
7
10
8
import numpy as np
@@ -4267,16 +4265,14 @@ def intersection(self, other):
4267
4265
return new_index
4268
4266
4269
4267
def _min_fitting_element (self , lower_limit ):
4270
- """Returns the value of the smallest element greater than the limit"""
4271
- round = ceil if self ._step > 0 else floor
4272
- no_steps = round ((float (lower_limit ) - self ._start ) / self ._step )
4273
- return self ._start + self ._step * no_steps
4268
+ """Returns the smallest element greater than or equal to the limit"""
4269
+ no_steps = - (- (lower_limit - self ._start ) // abs (self ._step ))
4270
+ return self ._start + abs (self ._step ) * no_steps
4274
4271
4275
4272
def _max_fitting_element (self , upper_limit ):
4276
- """Returns the value of the largest element smaller than the limit"""
4277
- round = floor if self ._step > 0 else ceil
4278
- no_steps = round ((float (upper_limit ) - self ._start ) / self ._step )
4279
- return self ._start + self ._step * no_steps
4273
+ """Returns the largest element smaller than or equal to the limit"""
4274
+ no_steps = (upper_limit - self ._start ) // abs (self ._step )
4275
+ return self ._start + abs (self ._step ) * no_steps
4280
4276
4281
4277
def _extended_gcd (self , a , b ):
4282
4278
"""
Original file line number Diff line number Diff line change @@ -4266,6 +4266,11 @@ def test_min_fitting_element(self):
4266
4266
result = RangeIndex (5 , 0 , - 1 )._min_fitting_element (1 )
4267
4267
self .assertEqual (1 , result )
4268
4268
4269
+ big_num = 500000000000000000000000
4270
+
4271
+ result = RangeIndex (5 , big_num * 2 , 1 )._min_fitting_element (big_num )
4272
+ self .assertEqual (big_num , result )
4273
+
4269
4274
def test_max_fitting_element (self ):
4270
4275
result = RangeIndex (0 , 20 , 2 )._max_fitting_element (17 )
4271
4276
self .assertEqual (16 , result )
@@ -4279,6 +4284,11 @@ def test_max_fitting_element(self):
4279
4284
result = RangeIndex (5 , 0 , - 1 )._max_fitting_element (4 )
4280
4285
self .assertEqual (4 , result )
4281
4286
4287
+ big_num = 500000000000000000000000
4288
+
4289
+ result = RangeIndex (5 , big_num * 2 , 1 )._max_fitting_element (big_num )
4290
+ self .assertEqual (big_num , result )
4291
+
4282
4292
def test_pickle_compat_construction (self ):
4283
4293
# RangeIndex() is a valid constructor
4284
4294
pass
You can’t perform that action at this time.
0 commit comments