ianhi / ianhi/xarray-linked-indexes
DimensionInterval breaks when `intervals` shares a `dim` with another `coord`
- Dominant language
- Python
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
## Context
A crucial requirement for the Interval Index is the ability to select by `word` not just intervals. For example in this case:
A simple approach is to create a custom index that keeps `word` and `intervals` in sync. However, that adds complexity and makes this less general and reusable by other use cases. Instead, we can swap the dimensions a bit. Instead of having `intervals` have `dim=intervals` we set `word` as the dimension coord.
This allows you to `sel` or `isel` on `word` which is the most meaningful space for these users to be selecting over.
## Problem
I'm struggling to get `sel/isel` to work in this case when I select based on either `intervals` or `time`. Seemingly because our indexer isn't able to convey that `word` also needs to be sliced at the same time as `intervals`.
Using the built in example dataset:
```python
from linked_indices.interval_index import DimensionInterval
from linked_indices.util import interval_dataset
ds = interval_dataset(interval_dim="word")
ds = ds.drop_indexes(["time"]).set_xindex(
["time", "intervals"],
DimensionInterval,
)
ds
```
doing
`ds.isel(time=5)`
gives
`ValueError: conflicting sizes for dimension 'word': length 1 on 'intervals' and length 4 on {'word': 'word', 'time': 'time'}`
but we can fake it by manually slicing word and everything works.
`ds.isel(time=5, word=0)`
we need to find a way to have that happen automatiaclly. I think it could be managed for `sel`, but I don't think that `isel`'s return value is not expressive enough for the index to handle this on it's own.
Similarly
`ds.sel(time=5)`
gives
`ValueError: dimension 'word' already exists as a scalar variable`
and
`ds.sel(time=slice(1,20))`
`ValueError: conflicting sizes for dimension 'word': length 1 on 'intervals' and length 4 on {'word': 'word', 'time': 'time'}`
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with linked_indices.interval_index.DimensionInterval and reproduce the reported cases using linked_indices.util.interval_dataset(interval_dim="word"). Run ds.isel(time=5), ds.sel(time=5), and ds.sel(time=slice(1,20)) after setting the x-indexes as shown. Done means selecting by time or intervals automatically keeps word and intervals aligned without the reported dimension conflicts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100