Skip to content

Enforce axis constraint in merge function #135

Open
@Balinus

Description

@Balinus

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions