Allow grouping noisy arrays using tolerances
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- numpy, python
- Domain
- data-engineering
Research direction
Start by locating the array groupby API and its grouping implementation. Compare the proposed groupby_isclose_argsort example with current grouping behavior, including the noted dask limitation. Done means tolerance parameters such as atol and rtol are supported through the groupby API and produce the intended groups for noisy arrays.
Written by the indexing model from the issue text.
Description
I find grouping data can be a little more intuitive when using tolerances.
This can be done for example like this:
def groupby_isclose_argsort(arr, atol=0, rtol=0.1):
"""
Return a group idx of a noisy array.
TODO: argsort not available in dask.
Examples
--------
reps = 2
y = np.array([72, 72, 100, 100, 300, 300, 500, 500])
y = np.stack(reps*[y], 0)
noise = lambda y : 1 + 0.1 * (np.random.rand(*y.shape) - 0.5)
y = y * noise(y)
groupby_isclose_argsort(y)
array([[0, 0, 1, 1, 2, 2, 3, 3],
[0, 0, 1, 1, 2, 2, 3, 3]], dtype=int32)
"""
# Sort values to make sure values are monotonically increasing:
a = arr.ravel()
i = np.argsort(a)
i_rev = np.empty(i.shape, dtype=np.intp, like=a)
i_rev[i] = np.arange(len(a), like=a)
a = a[i]
# Calculate a monotonically increasing index that increase when the
# difference between current and previous value changes:
b = np.roll(a, 1)
b[0] = a[0]
by = np.cumsum(~np.isclose(a, b, atol=atol, rtol=rtol))
# tolerance = atol + rtol * b
# by = np.cumsum(np.abs(a - b) > tolerance)
return by[i_rev].reshape(arr.shape)
So on a dataset the api would look something like this ds.groupby("arr", atol=0, rtol=0.1).
- Dominant language
- Python
- Stars
- 137
- Forks
- 24
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from xarray-contrib/flox
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
xarray-contrib/flox#516 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
xarray-contrib/flox#501 ·
-
expr Open
Difficulty 5/5 Over a week Newbie friendliness 20/100
xarray-contrib/flox#482 · 32 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
xarray-contrib/flox#479 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
xarray-contrib/flox#449 ·
All issues in xarray-contrib/flox
Similar issues
-
area/auth bug comp/agent P3 platform/discord type/security
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
NousResearch/hermes-agent#117848 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100