Skip to content

Commit 1d06991

Browse files
committed
ENH: Generalize RangeIndex to support floats pandas-dev#46484
1 parent c68c626 commit 1d06991

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pandas/core/indexes/float_range.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class float_range:
2+
'''
3+
Modified Python built-in function range that accepts floats as arguments.
4+
5+
Parameters
6+
----------
7+
start : float (default: 0)
8+
If "stop" is not given, interpreted as "stop" instead.
9+
stop : float (default: 0)
10+
step : float (default: 1)
11+
12+
Attributes
13+
----------
14+
start
15+
stop
16+
step
17+
current
18+
'''
19+
def __init__(self, start=0, stop=0, step=1):
20+
if start and not stop:
21+
stop, start = start, 0
22+
self.start = start
23+
self.current = start - step
24+
self.stop = stop
25+
self.step = step
26+
27+
def __iter__(self):
28+
return self
29+
30+
def __next__(self):
31+
self.current += self.step
32+
if self.current < self.stop:
33+
return self.current
34+
raise StopIteration

0 commit comments

Comments
 (0)