-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add RangeIndex #10076
base: main
Are you sure you want to change the base?
Add RangeIndex #10076
Conversation
- Use start, stop, step terms - Make RangeIndex.__init__ private and more flexible, add RangeIndex.arange and RangeIndex.linspace public factories - General support of RangeIndex slicing - RangeIndex.isel with arbitrary 1D values: convert to PandasIndex - Add RangeIndex.to_pandas_index
... when check_default_indexes=False.
I've made further progress on this. Some design questions (thoughts welcome!): Create a new RangeIndex
import xarray as xr
from xarray.indexes import RangeIndex
index = RangeIndex.arange("x", "x", 0.0, 1.0, 0.1)
ds = xr.Dataset(coords=xr.Coordinates.from_xindex(index))
Index importShould we expose all public built-in Xarray indexes at the top level? Or only at the Currently the |
Note: this Xarray RangeIndex is designed for floating value ranges. For integer ranges it is probably best to use a PandasIndex wrapping a |
dim : str | ||
Dimension name. | ||
start : float, optional | ||
Start of interval (default: 0.0). The interval includes this value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could consider adding a closed
kwarg like pd.Interval, but in a future PR of course.
"`Coordinates.from_xindex()`" | ||
) | ||
|
||
@property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these all be cached_property
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would there be much benefit of caching those simple aliases to attributes of the underlying transform
?
Make `dim` a required keyword argument and `coord_name` an optional keyword argument (defaults to `dim`).
dtype : dtype, optional | ||
The dtype of the coordinate variable (default: float64). | ||
|
||
Examples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Examples | |
Note that all `start`, `stop` & `step` must be passed, which is more explicit than `np.arange` or `range` | |
Examples |
(optional, no strong view)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that all
start
,stop
&step
must be passed
This isn't exactly true, but yes the API here is more explicit than np.arange
and range
, e.g., RangeIndex.arange(10.0)
means start=10 while np.arange(10.0)
means stop=10.
RangeIndex.arange(10.0)
doesn't make much sense, though, considering the default value of stop=1.0. I'll see if we can get closer to np.arange
using tpying.overload
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RangeIndex.arange(10.0)
doesn't make much sense, though, considering the default value of stop=1.0. I'll see if we can get closer tonp.arange
usingtpying.overload
.
yeah. no objection to the more explicit approach — it's useful-but-a-bit-magic that arange
/ range
changes the meaning of the first arg based on how many are supplied
whats-new.rst
api.rst
Work in progress (justReady for review (copied and adapted the example from #9543 (comment)).