-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Generalize RangeIndex to support floats #46484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
Hi! In order to make this happen I think we should modify Python's built-in function |
+1 on the idea. FWIW A while back I tried to introduce a RangeEngine to allow for getting more code out of RangeIndex. Ran into a problem that cython doesn't recognize 'range' as a type, xref cython/cython#4040 |
This modification of class float_range():
def __init__(self, start=0, stop=None, step=1):
self.start = start
self.current = start - step
self.stop = stop
self.step = step
def __iter__(self):
return self
def __next__(self):
self.current += self.step
if self.current < self.stop:
return self.current
raise StopIteration Example: rng = float_range(0, 2, 0.5)
for r in rng:
print(r) Output:
|
marianna13
added a commit
to marianna13/pandas
that referenced
this issue
Mar 28, 2022
take |
kapiliyer
added a commit
to kapiliyer/pandas
that referenced
this issue
Aug 12, 2022
kapiliyer
added a commit
to kapiliyer/pandas
that referenced
this issue
Aug 12, 2022
kapiliyer
added a commit
to kapiliyer/pandas
that referenced
this issue
Aug 12, 2022
kapiliyer
added a commit
to kapiliyer/pandas
that referenced
this issue
Aug 12, 2022
kapiliyer
added a commit
to kapiliyer/pandas
that referenced
this issue
Aug 15, 2022
kapiliyer
added a commit
to kapiliyer/pandas
that referenced
this issue
Aug 15, 2022
float_range class indexing/slicing support
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem?
When working with geospatial data in xarray, it's common to have regularly-spaced, floating-point coordinates. Using a RangeIndex with floating-point start, stop, and step would cut down on the memory usage. https://github.com/gjoseph92/stackstac/blob/1c6553a5b6b2acbb89388bd8b1c2d280ea2f3bd5/stackstac/prepare.py#L412
Describe the solution you'd like
Let RangeIndex accept floating point start, stop, and step. Will need to change a handful of other methods to support the generalization (e.g.
inferred_type
, probably some of the hashtable stuff).API breaking implications
None.
Describe alternatives you've considered
Reimplementing all of the index classes to support an "encoding" scheme, which would subsume range encoding, categorical encoding, ... But that's a ton of work :)
Additional context
The text was updated successfully, but these errors were encountered: