Enforce axis constraint in merge function

Open
#135 2 comments 1 reaction 0 assignees View on GitHub

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
julia
Domain
data

Research direction

Start by reproducing the merge(B, A) and sort(M) examples from the issue, then inspect the merge and sort entry points in AxisArrays.jl. The change is complete when a caller can enforce the :time axis as an ascending sort constraint during merge operations, including merges with more than two inputs.

Written by the indexing model from the issue text.

Description

bug

Hello!

I'm wondering if there is a way to easily keep one of the axis as a "sort" axis constraint in merge operations. Here's an example of what is the current behavior:

A = AxisArray(collect(1:11), Axis{:time}(0:0.1:1))
B = AxisArray(collect(12:22), Axis{:time}(1.1:0.1:2.1))
M = merge(B, A) # ideally, I would like to force the time axis to an ascending order

1-dimensional AxisArray{Int64,1,...} with axes:
    :time, [1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0  …  0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
And data, a 22-element Array{Int64,1}:
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
  ⋮
  3
  4
  5
  6
  7
  8
  9
 10
 11

Now, trying sort(M) returns

sort(M)
1-dimensional AxisArray{Int64,1,...} with axes:
    :time, [1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0  …  0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
And data, a 22-element Array{Int64,1}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
  ⋮
 14
 15
 16
 17
 18
 19
 20
 21
 22

Hence, the values are sorted, but not the time axis definition.

Ideally, I would like to enforce the :time axis to be the sorting constraint in merge function.

I coded a workaround in a custom merge function which consist of reverting the order of the argument (i.e. merge(B, A) -> merge(A, B)). But I suspect that it only works for 2-input call to merge without a more complex workaround.

Thanks for any help or hint on how it can be done!

Dominant language
Julia
Stars
207
Forks
41
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaArrays/AxisArrays.jl

All issues in JuliaArrays/AxisArrays.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.