DataCubes
Exported
DataCubes.axis2flds ¶
axis2flds(arr::LabeledArray (; name_collapse_function=..., default_axis_value=nothing)
Collapse a dimension of a LabeledArray, making the axis along that direction as field names.
Arguments
larr: a LabeledArray.name_collapse_function(optional keyword) : a function to combine the axis label and the column name. By default, it concatenates the names with '_' inserted in between.default_axis_value(optional keyword) : a default value to be used when an axis element is null. Ifnothing(by default), an exception will raise.
Examples
julia> t = larr(reshape(1:10,5,2), axis1=darr(k=['a','b','c','d','e']), axis2=darr(r1=[:M,:N],r2=["A","A"]))
5 x 2 LabeledArray
r1 |M |N
r2 |A |A
---+--+---
k | |
---+--+---
a |1 |6
b |2 |7
c |3 |8
d |4 |9
e |5 |10
julia> axis2flds(t)
5 LabeledArray
k |M_A N_A
--+--------
a |1 6
b |2 7
c |3 8
d |4 9
e |5 10
julia> axis2flds(t, name_collapse_function=x->join(x, "*"))
5 LabeledArray
k |M*A N*A
--+--------
a |1 6
b |2 7
c |3 8
d |4 9
e |5 10
julia> m = @larr(reshape(1:10,5,2), axis1[k=['a','b','c','d','e']], axis2[:M,NA])
5 x 2 LabeledArray
|M |
--+--+---
k | |
--+--+---
a |1 |6
b |2 |7
c |3 |8
d |4 |9
e |5 |10
julia> axis2flds(m, default_axis_value="N/A")
5 LabeledArray
k |M N/A
--+------
a |1 6
b |2 7
c |3 8
d |4 9
e |5 10
source: DataCubes/src/util/array_util.jl:619
DataCubes.collapse_axes ¶
collapse_axes(arr::AbstractArray, front_dim::Integer, back_end::Integer)
Collapse front_dim to back_dim dimensions into one.
Arguments
arr: an arrayfront_dims: the starting direction to collapse.back_dims: the end direction to collapse.
The result is an array whose elements along front_dims to back_dims are all flattened into one dimension.
If arr is a LabeledArray, all the labels along the flattened direction are combined together.
Examples
julia> collapse_axes(darr(a=reshape(1:40, 2,4,5), b=reshape(11:50, 2,4,5)), 1, 2)
8 x 5 DictArray
a b |a b |a b |a b |a b
-----+------+------+------+------
1 11 |9 19 |17 27 |25 35 |33 43
2 12 |10 20 |18 28 |26 36 |34 44
3 13 |11 21 |19 29 |27 37 |35 45
4 14 |12 22 |20 30 |28 38 |36 46
5 15 |13 23 |21 31 |29 39 |37 47
6 16 |14 24 |22 32 |30 40 |38 48
7 17 |15 25 |23 33 |31 41 |39 49
8 18 |16 26 |24 34 |32 42 |40 50
source: DataCubes/src/util/array_util.jl:192
DataCubes.darr ¶
darr(...)
Create a DictArray. The arguments ... can be one of the following:
Arguments
k=>vcreates a field using an arrayvwith field namek.kcan be an arbitrary type. If the element type ofvis notNullable, each element will be wrapped byNullable. If you want to manually provide aNullablearray withNullable{T}()elements in it, the macro version@darrmay be more convenient to use. Note that this type of argument precedes the keyword type argument in the returnDictArray, as shown in Examples below.k=vcreates a field using an arrayvwith field name:k.- There can be at most one non pair type argument, which will be converted into a
DictArrayand other pair arguments will update it. Especially, if the non pair type argument is an array ofLDict, it will be converted into aDictArray.
Examples
julia> t = darr(a=[1 2;3 4;5 6],b=["abc" 'a';1 2;:m "xyz"],:c=>[1.0 1.5;:sym 'a';"X" "Y"])
3 x 2 DictArray
c a b |c a b
----------+----------
1.0 1 abc |1.5 2 a
sym 3 1 |a 4 2
X 5 m |Y 6 xyz
julia> darr(t, c=[1 2;3 4;5 6], :d=>map(Nullable, [1 2;3 4;5 6]))
3 x 2 DictArray
c a b d |c a b d
----------+----------
1 1 abc 1 |2 2 a 2
3 3 1 3 |4 4 2 4
5 5 m 5 |6 6 xyz 6
julia> darr(Any[LDict(:a => Nullable(1),:b => Nullable{Int}()),LDict(:a => Nullable(3),:b => Nullable(4))])
2 DictArray
a b
----
1
3 4
source: DataCubes/src/datatypes/dict_array.jl:1214
DataCubes.delete ¶
Delete keys or fields from LDict, DictArray, or LabeledArray.
delete(dict::LDict, keys...)deletes the keyskeysfromdictand returns a newLDict.delete(arr::DictArray, fieldnames...)deletes the fields forfieldnamesfromarrand returns a newDictArray.delete(arr::LabeledArray, fieldnames...)deletes the fields forfieldnamesfromarr, either from the base or axes, and returns a newLabeledArray.
Examples
julia> delete(LDict(:a=>1, :b=>2, :c=>3), :a, :c)
DataCubes.LDict{Symbol,Int64} with 1 entry:
:b => 2
julia> delete(darr(a=[1,2,3], b=[:m,:n,:p]), :b)
3 DictArray
a
--
1
2
3
julia> t = larr(a=[1 2;3 4;5 6], b=[:x :y;:z :u;:v :w], axis1=darr(k=["X","Y","Z"]), axis2=[:A,:B])
3 x 2 LabeledArray
|A |B
--+----+----
k |a b |a b
--+----+----
X |1 x |2 y
Y |3 z |4 u
Z |5 v |6 w
julia> delete(t, :k, :b)
3 x 2 LabeledArray
|A |B
--+--+--
|a |a
--+--+--
1 |1 |2
2 |3 |4
3 |5 |6
source: DataCubes/src/util/array_util.jl:1054
DataCubes.describe ¶
describe(arr)
Generate a LabeledArray showing the overall statistics of the input.
If the input is a Nullable array, its summary statistics is calculated and the return value is of type LDict.
If the input is a DictArray, the summary is calculated for each field and the result is a DictArray.
If the input is a LabeledArray, describe returns the summary of its base.
Examples
julia> describe(@nalift([1,2,3,4,NA]))
DataCubes.LDict{Symbol,Any} with 10 entries:
:min => [Nullable(1)]
:q1 => Nullable(1.75)
:med => Nullable(2.5)
:q3 => Nullable(3.25)
:max => Nullable(4)
:mean => Nullable(2.5)
:std => Nullable(1.2909944487358056)
:count => Nullable(5)
:nacount => Nullable(1)
:naratio => Nullable(0.2)
julia> describe(@darr(a=[1,2,3,4,NA],b=[1,2,3,4,5]))
2 LabeledArray
|min q1 med q3 max mean std count nacount naratio
--+--------------------------------------------------------------------
a |1 1.75 2.5 3.25 4 2.5 1.2909944487358056 5 1 0.2
b |1 2.0 3.0 4.0 5 3.0 1.5811388300841898 5 0 0.0
julia> describe(@larr(a=[1,2,3,4,NA],b=[1,2,3,4,5],axis1[:m,:n,:p,:q,:r]))
2 LabeledArray
|min q1 med q3 max mean std count nacount naratio
--+--------------------------------------------------------------------
a |1 1.75 2.5 3.25 4 2.5 1.2909944487358056 5 1 0.2
b |1 2.0 3.0 4.0 5 3.0 1.5811388300841898 5 0 0.0
source: DataCubes/src/util/array_helper_functions.jl:1735
DataCubes.discard ¶
discard(arr, ns...)
Discard a block of array discarding all elements specified by ns..., using labels for LabeledArrays, indices for other types of arrays or LDicts.
Arguments
arr: anAbstractArrayorLDict.ns...: each element innschooses specific elements along that direction. The element can beColon()(:): the entire range will be removed and the return value will be empty.- a label or array of labels along that direction to discard.
- a boolean array of the same size as the axis along that direction to denote which position to discard.
- a function that takes the axis along that direction and generates either an array of integers or a boolean array for the deleted positions.
Return
An array or LDict of the same type as arr, which is selected based on ns.... All indices will be chosen for the rest of the directions not specified in ns.... If any label is missing or the integer range is out of bound, it will be ignored.
Examples
julia> t = larr(a=map(x->'a'+x,reshape(0:14,5,3)), b=reshape(1:15,5,3), axis1=[:X,:Y,:Z,:U,:V], axis2=darr(r1=[:A,:A,:B],r2=[:m,:n,:n]))
5 x 3 LabeledArray
r1 |A |A |B
r2 |m |n |n
---+----+-----+-----
|a b |a b |a b
---+----+-----+-----
X |a 1 |f 6 |k 11
Y |b 2 |g 7 |l 12
Z |c 3 |h 8 |m 13
U |d 4 |i 9 |n 14
V |e 5 |j 10 |o 15
julia> discard(t, [:X,:V,:W], map(Nullable,(:A,:m)))
3 x 2 LabeledArray
r1 |A |B
r2 |n |n
---+----+-----
|a b |a b
---+----+-----
Y |g 7 |l 12
Z |h 8 |m 13
U |i 9 |n 14
julia> discard(t, [:X,:V,:W], darr(r1=[:A,:B],r2=[:m,:m]))
3 x 2 LabeledArray
r1 |A |B
r2 |n |n
---+----+-----
|a b |a b
---+----+-----
Y |g 7 |l 12
Z |h 8 |m 13
U |i 9 |n 14
julia> discard(t, [], d->d[:r1] .== :A)
5 x 1 LabeledArray
r1 |B
r2 |n
---+-----
|a b
---+-----
X |k 11
Y |l 12
Z |m 13
U |n 14
V |o 15
source: DataCubes/src/util/array_util.jl:1676
DataCubes.dropna ¶
Remove any NA entries. If all elements are NA along some slice, that slice will be removed and the array size will shrink.
Examples
julia> t = @darr(a=[1 2 NA;NA 5 NA], b=[NA :n NA;:x NA NA])
2 x 3 DictArray
a b |a b |a b
----+----+----
1 |2 n |
x |5 |
julia> dropna(t)
2 x 2 DictArray
a b |a b
----+----
1 |2 n
x |5
julia> m = @larr(a=[1 2 NA;NA 5 NA], b=[NA :n NA;:x NA NA], axis1[:M,:N])
d2 x 3 LabeledArray
|1 |2 |3
--+----+----+----
|a b |a b |a b
--+----+----+----
M |1 |2 n |
N | x |5 |
julia> dropna(m)
2 x 2 LabeledArray
|1 |2
--+----+----
|a b |a b
--+----+----
M |1 |2 n
N | x |5
source: DataCubes/src/util/array_util.jl:1142
DataCubes.enumeration ¶
enumeration(arr [, poolorder])
Create an EnumerationArray.
Arguments
arr: an input array ofNullableelement type. It is assumed that there are only a few possible values inarrand each value is converted into an integer when creating anEnumerationArray.poolorder: a vector to fix some of the integer values in the mapping from the values inarrto integers. If there arenelements inpoolorder, thosenelements inarrwill be assigned 1...nwhen creating anEnumerationArray. All the others are assigned integers in order of their appearance.
Examples
julia> enumeration([:A,:A,:B,:B,:C])
5-element DataCubes.EnumerationArray{Symbol,1,DataCubes.AbstractArrayWrapper{Int64,1,Array{Int64,1}},Int64}:
Nullable(:A)
Nullable(:A)
Nullable(:B)
Nullable(:B)
Nullable(:C)
julia> enumeration([:A,:A,:B,:B,:C]).pool
3-element Array{Symbol,1}:
:A
:B
:C
julia> enumeration([:A,:A,:B,:B,:C]).elems
5-element DataCubes.AbstractArrayWrapper{Int64,1,Array{Int64,1}}:
1
1
2
2
3
julia> enumeration([:A,:A,:B,:B,:C], [:C,:B])
5-element DataCubes.EnumerationArray{Symbol,1,DataCubes.AbstractArrayWrapper{Int64,1,Array{Int64,1}},Int64}:
Nullable(:A)
Nullable(:A)
Nullable(:B)
Nullable(:B)
Nullable(:C)
julia> enumeration([:A,:A,:B,:B,:C], [:C,:B]).pool
3-element Array{Symbol,1}:
:C
:B
:A
julia> enumeration([:A,:A,:B,:B,:C], [:C,:B]).elems
5-element DataCubes.AbstractArrayWrapper{Int64,1,Array{Int64,1}}:
3
3
2
2
1
source: DataCubes/src/datatypes/enumeration_array.jl:202
DataCubes.extract ¶
extract(arr, ns...)
Extract a block of array using labels for LabeledArrays, indices for other types of arrays or LDicts.
Arguments
arr: anAbstractArrayorLDict.ns...: each element innschooses specific elements along that direction. The element can beColon()(:): the entire range.- a label along that direction. If the axis along the direction is
DictArray, the label can be either anLDictfor its element or a tuple to denote the values ofLDict. - array of labels along that direction.
- a boolean array of the same size as the axis along that direction to denote which position to choose.
- a function that takes the axis along that direction and generates either an array of integers or a boolean array for the selected positions.
Return
An array or LDict of the same type as arr, which is selected based on ns.... All indices will be chosen for the rest of the directions not specified in ns.... If any label is missing or the integer range is out of bound, NA will be used for that element in the return value. If an element in ns is scalar, the dimension along that direction will be collapsed just as in slice.
Examples
julia> t = larr(a=map(x->'a'+x,reshape(0:14,5,3)), b=reshape(1:15,5,3), axis1=[:X,:Y,:Z,:U,:V], axis2=darr(r1=[:A,:A,:B],r2=[:m,:n,:n]))
5 x 3 LabeledArray
r1 |A |A |B
r2 |m |n |n
---+----+-----+-----
|a b |a b |a b
---+----+-----+-----
X |a 1 |f 6 |k 11
Y |b 2 |g 7 |l 12
Z |c 3 |h 8 |m 13
U |d 4 |i 9 |n 14
V |e 5 |j 10 |o 15
julia> extract(t, [:X,:V,:W], map(Nullable,(:A,:m)))
3 LabeledArray
|a b
--+----
X |a 1
V |e 5
W |
julia> extract(t, [:X,:V,:W], darr(r1=[:A,:B],r2=[:m,:m]))
3 x 2 LabeledArray
r1 |A |B
r2 |m |m
---+----+----
|a b |a b
---+----+----
X |a 1 |
V |e 5 |
W | |
julia> extract(t, :, d->d[:r1] .== :A)
5 x 2 LabeledArray
r1 |A |A
r2 |m |n
---+----+-----
|a b |a b
---+----+-----
X |a 1 |f 6
Y |b 2 |g 7
Z |c 3 |h 8
U |d 4 |i 9
V |e 5 |j 10
source: DataCubes/src/util/array_util.jl:1466
DataCubes.flds2axis ¶
flds2axis(arr::LabeledArray [; axisname=nothing, fieldname=nothing])
Create another dimension using the field values of the data of a LabeledArray.
Arguments
arr: aLabeledArray.axisname(optional) : the name of the new axis.fieldname(optional) : the name of the new field name. If not specified, the resultingLabeledArraywill have a normalAbstractArrayand not aDictArrayas its data.
Returns
A new LabeledArray which has one higher dimensions than the input arr.
The field names become the elements of the new last axis, after wrapped by Nullable.
If axisname is provided, the new axis becomes a DictArray with that field name.
Otherwise, the new axis will be a normal array.
If fieldname is provided, the new data of the return LabeledArray is a DictArray with that field name.
Otherwise, the new data will be a normal array.
Examples
julia> t = larr(a=[1,2,3], b=[:x,:y,:z])
3 LabeledArray
|a b
--+----
1 |1 x
2 |2 y
3 |3 z
julia> flds2axis(t, axisname=:newaxis, fieldname=:newfield)
3 x 2 LabeledArray
newaxis |a |b
--------+---------+---------
|newfield |newfield
--------+---------+---------
1 |1 |x
2 |2 |y
3 |3 |z
source: DataCubes/src/util/array_util.jl:514
DataCubes.igna ¶
igna(arr [, nareplace])
Ignore null elements from arr.
Null elements will be replaced by nareplace, if provided.
If not, the behavior is implementation specific: depending on the array type, it may give some default value or raise an error.
Most likely, a nullable element in an array of Nullable{F} element type for some AbstractFloat F can be replaced by a version of NaN.
But for other types, it may be better to raise an error.
-
igna(arr::AbstractArray{Nullable{T},N} [, na_replace]): ignores null elements fromarrand return anAbstractArray{T,N}. A null value is replaced byna_replaceif provided. Otherwise, the result is implementation specific. -
igna(ldict::LDict [, na_replace])ignores null values fromldictand replace them withna_replaceif provided. Otherwise, the result is implementation specific.
Examples
julia> igna(@nalift([1,2,NA,4,5]))
ERROR: DataCubes.NAElementException()
in anonymous at /Users/changsoonpark/.julia/v0.4/DataCubes/src/na/na.jl:315
in map_to! at abstractarray.jl:1289
in map at abstractarray.jl:1311
in igna at /Users/changsoonpark/.julia/v0.4/DataCubes/src/na/na.jl:313
julia> igna(@nalift([1.0,2.0,NA,4.0,5.0]))
5-element DataCubes.AbstractArrayWrapper{Float64,1,Array{Float64,1}}:
1.0
2.0
NaN
4.0
5.0
julia> igna(@nalift([1,2,NA,4,5]), 3)
5-element DataCubes.AbstractArrayWrapper{Int64,1,Array{Int64,1}}:
1
2
3
4
5
julia> igna(LDict(:a=>Nullable(3), :b=>Nullable{Int}()), 1)
DataCubes.LDict{Symbol,Int64} with 2 entries:
:a => 3
:b => 1
source: DataCubes/src/na/na.jl:525
DataCubes.ignabool ¶
ignabool(arr)
Ignore the Nullable part of of either a Nullable array or a Nullable variable.
It is mainly used in the condition statement for @select or @update, where it assumes that only Nullable(true) chooses the element. Nullable(false) or Nullable{T}() will be regarded as false.
ignabool(::AbstractArray{Nullable{Bool}}) returns anAbstractArray{Bool}where null andNullable(false)elements are converted intofalseandNullable(true)intotrue`.ignabool(::Nullable{Bool})converts null andNullable(false)elements intofalseandNullable(true)into true.
Examples
julia> ignabool(Nullable{Bool}())
false
julia> ignabool(Nullable(true))
true
julia> ignabool(Nullable(false))
false
julia> ignabool(@nalift([true true NA;false NA true]))
2x3 DataCubes.AbstractArrayWrapper{Bool,2,Array{Bool,2}}:
true true false
false false true
source: DataCubes/src/na/na.jl:613
DataCubes.innerjoin ¶
innerjoin(base, src, join_axis...)
Inner join an LabeledArray into another LabeledArray. innerjoin is different from leftjoin in that only elements in the left array that have the corresponding elements in the right array will be kept. Otherwise, the elements will be set to null. If the entire elements along some direction are null, they will be all removed in the output.
Note that the left array (base) can be multidimensional. The function creates a dictionary from the right array (src).
Arguments
base: the leftLabeledArray.src: the rightLabeledArray.join_axes...can be one of the following forms:- integers for the directions in
srcalong which to join. - a list of integer=>integer or integer=>vector of arrays, each array of the same shape as
base.
- integers for the directions in
Ultimately, join_axes... produces pairs of direction in src => vector of arrays, each of the shape of base. If the value in key=>value is an integer, the axis along that direction in base is taken, after broadcast. The field values are combined into a vector of arrays. If the right hand side is missing (i.e. just an integer), the field names in the axis along the integer direction are used to create an array for base.
Return
An inner joined LabeledArray. The join is performed as follows: Given an i=>arr form as an element in join_axes, the keys in ith direction in src are used as keys and arr are used the keys in the base side to inner join. The values will be the sliced subarrays for each value in the join_axes. Note that join_axis... chooses multiple axes for keys.
The output number of dimensions is ndims(base) + ndims(src) - length(join_axes).
Note that when join_axis is empty, the result is the tensor product of base and src from tensorprod.
Examples
julia> b = larr(k=[:x :x :y;:z :u :v], axis1=[:x,:u], axis2=darr(r=[:x, :y, :z]))
2 x 3 LabeledArray
r |x |y |z
--+--+--+--
|k |k |k
--+--+--+--
x |x |x |y
u |z |u |v
julia> s = larr(axis1=darr(k=[:x,:y,:z,:m,:n,:p]), b=[1,2,3,4,5,6])
6 LabeledArray
k |b
--+--
x |1
y |2
z |3
m |4
n |5
p |6
julia> innerjoin(b, s, 1)
2 x 3 LabeledArray
r |x |y |z
--+----+----+----
|k b |k b |k b
--+----+----+----
x |x 1 |x 1 |y 2
u |z 3 |u |v
julia> innerjoin(b, s, 1=>1)
1 x 3 LabeledArray
r |x |y |z
--+----+----+----
|k b |k b |k b
--+----+----+----
x |x 1 |x 1 |y 1
julia> innerjoin(b, s, 1=>Any[nalift([:o :x :x;:q :r :y])])
2 x 2 LabeledArray
r |y |z
--+----+----
|k b |k b
--+----+----
x |x 1 |y 1
u |u |v 2
source: DataCubes/src/util/join.jl:260
DataCubes.isna ¶
isna(arr [, coords...])
Checks NA for each element and produces an AbstractArray{Bool} of the same shape as arr.
If coords... are provided, isna checks NA at that position.
- If an input array is
AbstractArray{Nullable{T}}, it checkes whether an element is null. - If an input array is
DictArray, it tests whether all values of the dictionary values for each element are null. - If an input array is
LabeledArray, it appliesisnato the base ofarr.
Examples
julia> t = @darr(a=[1 NA 3;4 5 NA], b=[NA NA :z;:u :v :w])
2 x 3 DictArray
a b |a b |a b
----+----+----
1 | |3 z
4 u |5 v | w
julia> isna(t)
2x3 DataCubes.AbstractArrayWrapper{Bool,2,Array{Bool,2}}:
false true false
false false false
julia> isna(t, 2, 2:3)
1x2 DataCubes.AbstractArrayWrapper{Bool,2,Array{Bool,2}}:
false false
julia> isna(@larr(t, axis1[NA,:Y], axis2[NA,NA,"W"]))
2x3 DataCubes.AbstractArrayWrapper{Bool,2,Array{Bool,2}}:
false true false
false false false
julia> isna(@nalift([1 2 NA;NA 5 6]))
2x3 DataCubes.AbstractArrayWrapper{Bool,2,Array{Bool,2}}:
false false true
true false false
source: DataCubes/src/na/na.jl:673
DataCubes.larr ¶
larr(...)
Create a LabeledArray. The arguments ... can be one of the following:
Arguments
k=>vcreates a field using arrayvwith field namekfor the underlying baseDictArray.kcan be an arbitrary type. If the element type ofvis notNullable, each element will be wrapped byNullable. If you want to manually provide aNullablearray withNullable{T}()elements in it, the macro version@larrmay be more convenient to use. Note that this type of argument precedes the keyword type argument in the returnLabeledArray, as shown in Examples below.k=vcreates a field using an arrayvwith field name:kfor the underlying baseDictArray.- The keyword
axisN=vfor some integerNand an arrayvis treated specially. This will create theNth axis using the arrayv. IfNinaxisNis omitted, the smallest available number is automatically chosen. - There can be at most one non pair type argument, which will be converted into a
LabeledArrayand other pair arguments will update it. Especially, if the non pair type argument is an array ofLDict, it will be converted into aDictArray.
Examples
julia> t = larr(a=[1 2;3 4;5 6],:b=>[1.0 1.5;:sym 'a';"X" "Y"],c=1,axis=[:U,:V,:W],axis2=darr(r=['m','n']))
3 x 2 LabeledArray
r |m |n
--+--------+--------
|b a c |b a c
--+--------+--------
U |1.0 1 1 |1.5 2 1
V |sym 3 1 |a 4 1
W |X 5 1 |Y 6 1
julia> larr(t, c=[1 2;3 4;5 6], :d=>:X, axis1=darr(k=["g","h","i"]))
3 x 2 LabeledArray
r |m |n
--+----------+----------
k |b a c d |b a c d
--+----------+----------
g |1.0 1 1 X |1.5 2 2 X
h |sym 3 3 X |a 4 4 X
i |X 5 5 X |Y 6 6 X
source: DataCubes/src/datatypes/labeled_array.jl:1470
DataCubes.leftjoin ¶
leftjoin(base, src, join_axis...)
Left join a LabeledArray into another LabeledArray.
Note that the left array (base) can be multidimensional. The function creates a dictionary from the right array (src).
Arguments
base: the leftLabeledArray.src: the rightLabeledArray.join_axes...can be one of the following forms:- integers for the directions in
srcalong which to join. In this case, the keys is thebaseside are found by matching the field names in the join directions insrcwith those inbase. - a list of integer=>integer or integer=>vector of arrays, each of the same shape as
base.
- integers for the directions in
Ultimately, join_axes... produces pairs of direction in src => vector of arrays, each of the shape of base. If the value in key=>value is an integer, the axis along that direction in base is taken, after broadcast. The field values are combined into a vector of arrays. If the right hand side is missing (i.e. just an integer), the field names in the axis along the integer direction are used to create an array for base.
Return
A left joined LabeledArray. The join is performed as follows: Given an i=>arr form as an element in join_axes, the keys in ith direction in src are used as keys and arr are used the keys in the base side to left join. The values will be the sliced subarrays for each value in the join_axes. Note that join_axis... chooses multiple axes for keys.
The output number of dimensions is ndims(base) + ndims(src) - length(join_axes).
Note that when join_axis is empty, the result is the tensor product of base and src from tensorprod.
Examples
julia> b = larr(k=[:x :x :y;:z :u :v], axis1=[:x,:y], axis2=darr(r=[:x, :y, :z]))
2 x 3 LabeledArray
r |x |y |z
--+--+--+--
|k |k |k
--+--+--+--
x |x |x |y
y |z |u |v
julia> s = larr(axis1=darr(k=[:x,:y,:z,:m,:n,:p]), b=[1,2,3,4,5,6])
6 LabeledArray
k |b
--+--
x |1
y |2
z |3
m |4
n |5
p |6
julia> leftjoin(b, s, 1)
2 x 3 LabeledArray
r |x |y |z
--+----+----+----
|k b |k b |k b
--+----+----+----
x |x 1 |x 1 |y 2
y |z 3 |u |v
julia> leftjoin(b, s, 1=>1)
2 x 3 LabeledArray
r |x |y |z
--+----+----+----
|k b |k b |k b
--+----+----+----
x |x 1 |x 1 |y 1
y |z 2 |u 2 |v 2
julia> leftjoin(b, s, 1=>Any[nalift([:x :z :n;:y :m :p])])
2 x 3 LabeledArray
r |x |y |z
--+----+----+----
|k b |k b |k b
--+----+----+----
x |x 1 |x 3 |y 5
y |z 2 |u 4 |v 6
source: DataCubes/src/util/join.jl:85
DataCubes.mapna ¶
mapna(f::Function, args...)
Apply f to the nullable arrays args. It works similarly as map(f, args...) but unwraps Nullable from args. If any of elements are Nullable, f is Nullable, too.
Arguments
f::Function: a function to apply.args: nullable arrays.
Returns
A nullable array after applying f to elements of args for each index. f maps non-nullable value to either non-nullable or nullable one. If mapped to a non-nullable value, it will be wrapped by Nullable implicitly. If any element of args is NA, then the return value at that position will be NA, too.
Examples
julia> mapna((x,y)->x+y+1, @nalift([1 2 3;4 5 NA]), @nalift([NA 2 3;4 NA NA]))
2x3 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable{Int64}() Nullable(5) Nullable(7)
Nullable(9) Nullable{Int64}() Nullable{Int64}()
julia> mapna((x,y)->Nullable(x+y+1), @nalift([1 2 3;4 5 NA]), @nalift([NA 2 3;4 NA NA]))
2x3 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable{Int64}() Nullable(5) Nullable(7)
Nullable(9) Nullable{Int64}() Nullable{Int64}()
source: DataCubes/src/util/array_util.jl:1177
DataCubes.mapvalues ¶
mapvalues(f::Function, xs...)
Apply a function f to each tuple constructed from xs. Each element of xs will be of type LDict/DictArray/LabeledArray. The input tuple is constructed by combining the element in the same position in each xs (or the constant value in case it is not an array).
Returns
For each element x in xs,
- If
xisLDict,fis applied to each value and the result is againLDictwith the same keys and the new values. - If
xisDictArray,fis applied to each field. The return value will beDictArrayif the return value offis also anAbstractArray. Otherwise, anLDictwill be returned. - If
xisLabeledArray,mapvalues(f, _)is applied to the base ofx. The return value will beLabeledArraywith the same axes if the return value offis also anAbstractArray. Otherwise, anLDictwill be returned.
Examples
julia> mapvalues(x->x+1, LDict(:a=>1, :b=>2))
DataCubes.LDict{Symbol,Int64} with 2 entries:
:a => 2
:b => 3
julia> mapvalues(x->x .+ 1, darr(a=[1,2,3], b=[4,5,6]))
3 DictArray
a b
----
2 5
3 6
4 7
julia> mapvalues(x->x .+ 1, larr(a=[1,2,3], b=[4,5,6], axis1=[:m,:n,:p]))
3 LabeledArray
|a b
--+----
m |2 5
n |3 6
p |4 7
julia> mapvalues(sum, darr(a=[1,2,3], b=[4,5,6]))
DataCubes.LDict{Symbol,Nullable{Int64}} with 2 entries:
:a => Nullable(6)
:b => Nullable(15)
julia> mapvalues(sum, larr(a=[1,2,3], b=[4,5,6], axis=[:m,:n,:p]))
DataCubes.LDict{Symbol,Nullable{Int64}} with 2 entries:
:a => Nullable(6)
:b => Nullable(15)
julia> mapvalues((x,y)->2x.*y,darr(a=[1 2 3]),darr(a=[4 5 6]))
1 x 3 DictArray
a |a |a
--+---+---
8 |20 |36
source: DataCubes/src/util/array_util.jl:722
DataCubes.mmaximum ¶
mmaximum(arr, dims... [; rev=false, window=0]) for arr of type AbstractArrayWrapper/LabeledArray/DictArray.
Calculate moving maximum of arr using the last window elements, or cumulative maximum if window=0.
Arguments
arr:AbstractArrayWrapper/LabeledArray/DictArray, the input array. When applied toDictArray,mmaximumis applied to each field. When applied toLabeledArray,mmaximumis applied to the base.dims: by defaultdims=(1,). That is, moving maximum is performed in the first direction. Ifdims=(n1, n2,...), for each slice spanned along the directionsn1,n2, ..., moving maximum is taken along the leading dimension indimsfirst (i.e.minimum(dims)), and then the next dimension, and so on.rev: Ifrev=true, moving maximum is calculated backward starting for the last elements. By default,rev=false.window: Ifwindow>0, only the lastwindowelements, including the one in consideration, will be used to calculate moving maximum. Ifwindow=0,maximumcalculates the cumulative maximum.NAwill be ignored.
Examples
julia> mmaximum(@nalift([11,14,12,11,17]))
5-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable(11)
Nullable(14)
Nullable(14)
Nullable(14)
Nullable(17)
julia> mmaximum(@nalift([11,NA,12,11,17]))
5-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable(11)
Nullable(11)
Nullable(12)
Nullable(12)
Nullable(17)
julia> mmaximum(darr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 1, 2)
2 x 3 DictArray
a b |a b |a b
------+------+------
11 10 |14 10 |15 10
14 10 |15 10 |16 10
julia> mmaximum(larr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 2, 1, rev=true)
2 x 3 LabeledArray
|1 |2 |3
--+------+-----+-----
|a b |a b |a b
--+------+-----+-----
1 |16 10 |16 9 |16 8
2 |16 9 |16 8 |16 5
source: DataCubes/src/util/array_helper_functions.jl:1266
DataCubes.mmean ¶
mmean(arr, dims... [; rev=false, window=0]) for arr of type AbstractArrayWrapper/LabeledArray/DictArray.
Calculate moving mean of arr using the last window elements, or cumulative mean if window=0.
Arguments
arr:AbstractArrayWrapper/LabeledArray/DictArray, the input array. When applied toDictArray,mmeanis applied to each field. When applied toLabeledArray,mmeanis applied to the base.dims: by defaultdims=(1,). That is, moving mean is performed in the first direction. Ifdims=(n1, n2,...), for each slice spanned along the directionsn1,n2, ..., moving mean is taken along the leading dimension indimsfirst (i.e.mean(dims)), and then the next dimension, and so on.rev: Ifrev=true, moving mean is calculated backward starting for the last elements. By default,rev=false.window: Ifwindow>0, only the lastwindowelements, including the one in consideration, will be used to calculate moving mean. Ifwindow=0,meancalculates the cumulative mean.NAwill be ignored.
Examples
julia> mmean(@nalift([10,11,12,14,17]))
5-element DataCubes.AbstractArrayWrapper{Nullable{Float64},1,Array{Nullable{Float64},1}}:
Nullable(10.0)
Nullable(10.5)
Nullable(11.0)
Nullable(11.75)
Nullable(12.8)
julia> mmean(@nalift([10,NA,12,14,17]))
5-element DataCubes.AbstractArrayWrapper{Nullable{Float64},1,Array{Nullable{Float64},1}}:
Nullable(10.0)
Nullable(10.0)
Nullable(11.0)
Nullable(12.0)
Nullable(13.25)
julia> mmean(darr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 1, 2)
2 x 3 DictArray
a b |a b |a b
----------+-------------------------------------+---------
11.0 10.0 |12.333333333333334 8.666666666666666 |13.0 8.0
12.5 8.5 |13.0 8.0 |13.5 7.5
julia> mmean(larr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 2, 1, rev=true)
2 x 3 LabeledArray
|1 |2 |3
--+---------+-------------------------------------+---------
|a b |a b |a b
--+---------+-------------------------------------+---------
1 |13.5 7.5 |14.0 7.0 |14.5 6.5
2 |14.0 7.0 |14.666666666666666 6.333333333333333 |16.0 5.0
source: DataCubes/src/util/array_helper_functions.jl:1052
DataCubes.mmedian ¶
mmedian(arr, dims... [; rev=false, window=0]) for arr of type AbstractArrayWrapper/LabeledArray/DictArray.
Calculate moving median of arr using the last window elements, or cumulative median if window=0.
Arguments
arr:AbstractArrayWrapper/LabeledArray/DictArray, the input array. When applied toDictArray,mmedianis applied to each field. When applied toLabeledArray,mmedianis applied to the base.dims: by defaultdims=(1,). That is, moving median is performed in the first direction. Ifdims=(n1, n2,...), for each slice spanned along the directionsn1,n2, ..., moving median is taken along the leading dimension indimsfirst (i.e.minimum(dims)), and then the next dimension, and so on.rev: Ifrev=true, moving median is calculated backward starting for the last elements. By default,rev=false.window: Ifwindow>0, only the lastwindowelements, including the one in consideration, will be used to calculate moving median. Ifwindow=0,mediancalculates the cumulative median.NAwill be ignored.
Examples
julia> mmedian(@nalift([11,14,12,11,17]))
5-element DataCubes.AbstractArrayWrapper{Nullable{Float64},1,Array{Nullable{Float64},1}}:
Nullable(11.0)
Nullable(12.5)
Nullable(12.5)
Nullable(12.5)
Nullable(14.0)
julia> mmedian(@nalift([11,NA,12,11,17]))
5-element DataCubes.AbstractArrayWrapper{Nullable{Float64},1,Array{Nullable{Float64},1}}:
Nullable(11.0)
Nullable(11.0)
Nullable(11.5)
Nullable(11.5)
Nullable(12.0)
julia> mmedian(darr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 1, 2)
2 x 3 DictArray
a b |a b |a b
----------+---------+---------
11.0 10.0 |12.5 8.5 |14.0 8.5
12.5 8.5 |14.0 8.5 |14.5 8.5
julia> mmedian(larr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 2, 1, rev=true)
2 x 3 LabeledArray
|1 |2 |3
--+---------+---------+---------
|a b |a b |a b
--+---------+---------+---------
1 |14.5 8.5 |14.5 8.0 |14.5 6.5
2 |14.5 8.0 |14.5 6.5 |16.0 5.0
source: DataCubes/src/util/array_helper_functions.jl:1330
DataCubes.mmiddle ¶
mmiddle(arr, dims... [; rev=false, window=0]) for arr of type AbstractArrayWrapper/LabeledArray/DictArray.
Calculate moving middle of arr using the last window elements, or cumulative middle if window=0.
Arguments
arr:AbstractArrayWrapper/LabeledArray/DictArray, the input array. When applied toDictArray,mmiddleis applied to each field. When applied toLabeledArray,mmiddleis applied to the base.dims: by defaultdims=(1,). That is, moving middle is performed in the first direction. Ifdims=(n1, n2,...), for each slice spanned along the directionsn1,n2, ..., moving middle is taken along the leading dimension indimsfirst (i.e.minimum(dims)), and then the next dimension, and so on.rev: Ifrev=true, moving middle is calculated backward starting for the last elements. By default,rev=false.window: Ifwindow>0, only the lastwindowelements, including the one in consideration, will be used to calculate moving middle. Ifwindow=0,middlecalculates the cumulative middle.NAwill be ignored.
Examples
julia> mmiddle(@nalift([11,14,12,11,17]))
5-element DataCubes.AbstractArrayWrapper{Nullable{Float64},1,Array{Nullable{Float64},1}}:
Nullable(11.0)
Nullable(12.5)
Nullable(12.5)
Nullable(12.5)
Nullable(14.0)
julia> mmiddle(@nalift([11,NA,12,11,17]))
5-element DataCubes.AbstractArrayWrapper{Nullable{Float64},1,Array{Nullable{Float64},1}}:
Nullable(11.0)
Nullable(11.0)
Nullable(11.5)
Nullable(11.5)
Nullable(14.0)
julia> mmiddle(darr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 1, 2)
2 x 3 DictArray
a b |a b |a b
----------+---------+---------
11.0 10.0 |12.5 8.5 |13.0 8.0
12.5 8.5 |13.0 8.0 |13.5 7.5
julia> mmiddle(larr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 2, 1, rev=true)
2 x 3 LabeledArray
|1 |2 |3
--+---------+---------+---------
|a b |a b |a b
--+---------+---------+---------
1 |13.5 7.5 |14.0 7.0 |14.5 6.5
2 |14.0 7.0 |14.5 6.5 |16.0 5.0
source: DataCubes/src/util/array_helper_functions.jl:1395
DataCubes.mminimum ¶
mminimum(arr, dims... [; rev=false, window=0]) for arr of type AbstractArrayWrapper/LabeledArray/DictArray.
Calculate moving minimum of arr using the last window elements, or cumulative minimum if window=0.
Arguments
arr:AbstractArrayWrapper/LabeledArray/DictArray, the input array. When applied toDictArray,mminimumis applied to each field. When applied toLabeledArray,mminimumis applied to the base.dims: by defaultdims=(1,). That is, moving minimum is performed in the first direction. Ifdims=(n1, n2,...), for each slice spanned along the directionsn1,n2, ..., moving minimum is taken along the leading dimension indimsfirst (i.e.minimum(dims)), and then the next dimension, and so on.rev: Ifrev=true, moving minimum is calculated backward starting for the last elements. By default,rev=false.window: Ifwindow>0, only the lastwindowelements, including the one in consideration, will be used to calculate moving minimum. Ifwindow=0,minimumcalculates the cumulative minimum.NAwill be ignored.
Examples
julia> mminimum(@nalift([15,10,12,11,17]))
5-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable(15)
Nullable(10)
Nullable(10)
Nullable(10)
Nullable(10)
julia> mminimum(@nalift([15,NA,12,11,17]))
5-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable(15)
Nullable(15)
Nullable(12)
Nullable(11)
Nullable(11)
julia> mminimum(darr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 1, 2)
2 x 3 DictArray
a b |a b |a b
------+-----+-----
11 10 |11 7 |11 6
11 7 |11 6 |11 5
julia> mminimum(larr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 2, 1, rev=true)
2 x 3 LabeledArray
|1 |2 |3
--+-----+-----+-----
|a b |a b |a b
--+-----+-----+-----
1 |11 5 |12 5 |13 5
2 |12 5 |13 5 |16 5
source: DataCubes/src/util/array_helper_functions.jl:1202
DataCubes.mprod ¶
mprod(arr, dims... [; rev=false, window=0]) for arr of type AbstractArrayWrapper/LabeledArray/DictArray.
Calculate moving product of arr using the last window elements, or cumulative product if window=0.
Arguments
arr:AbstractArrayWrapper/LabeledArray/DictArray, the input array. When applied toDictArray,mprodis applied to each field. When applied toLabeledArray,mprodis applied to the base.dims: by defaultdims=(1,). That is, moving product is performed in the first direction. Ifdims=(n1, n2,...), for each slice spanned along the directionsn1,n2, ..., moving product is taken along the leading dimension indimsfirst (i.e.prod(dims)), and then the next dimension, and so on.rev: Ifrev=true, moving product is calculated backward starting for the last elements. By default,rev=false.window: Ifwindow>0, only the lastwindowelements, including the one in consideration, will be used to calculate moving product. Ifwindow=0,prodcalculates the cumulative product.NAwill be ignored.
Examples
julia> mprod(@nalift([10,11,12,14,17]))
5-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable(10)
Nullable(110)
Nullable(1320)
Nullable(18480)
Nullable(314160)
julia> mprod(@nalift([10,NA,12,14,17]))
5-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable(10)
Nullable(10)
Nullable(120)
Nullable(1680)
Nullable(28560)
julia> mprod(darr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 1, 2)
2 x 3 DictArray
a b |a b |a b
-------+-----------+---------------
11 10 |1848 630 |360360 30240
154 70 |27720 3780 |5765760 151200
julia> mprod(larr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 2, 1, rev=true)
2 x 3 LabeledArray
|1 |2 |3
--+---------------+-----------+-------
|a b |a b |a b
--+---------------+-----------+-------
1 |5765760 151200 |37440 2160 |208 40
2 |524160 15120 |3120 240 |16 5
source: DataCubes/src/util/array_helper_functions.jl:939
DataCubes.mquantile ¶
mquantile(arr, quantile, dims... [; rev=false, window=0]) for arr of type AbstractArrayWrapper/LabeledArray/DictArray.
Calculate moving quantile of arr using the last window elements, or cumulative quantile if window=0.
Arguments
arr:AbstractArrayWrapper/LabeledArray/DictArray, the input array. When applied toDictArray,mquantileis applied to each field. When applied toLabeledArray,mquantileis applied to the base.quantile: a number between 0 and 1 for the quantile to calculate.dims: by defaultdims=(1,). That is, moving quantile is performed in the first direction. Ifdims=(n1, n2,...), for each slice spanned along the directionsn1,n2, ..., moving quantile is taken along the leading dimension indimsfirst (i.e.minimum(dims)), and then the next dimension, and so on.rev: Ifrev=true, moving quantile is calculated backward starting for the last elements. By default,rev=false.window: Ifwindow>0, only the lastwindowelements, including the one in consideration, will be used to calculate moving quantile. Ifwindow=0,quantilecalculates the cumulative quantile.NAwill be ignored.
Examples
julia> mquantile(@nalift([11,14,12,11,17]), 0.25)
5-element DataCubes.AbstractArrayWrapper{Nullable{Float64},1,Array{Nullable{Float64},1}}:
Nullable(11.0)
Nullable(11.75)
Nullable(11.75)
Nullable(11.75)
Nullable(12.5)
julia> mquantile(@nalift([11,NA,12,11,17]), 0.25)
5-element DataCubes.AbstractArrayWrapper{Nullable{Float64},1,Array{Nullable{Float64},1}}:
Nullable(11.0)
Nullable(11.0)
Nullable(11.25)
Nullable(11.25)
Nullable(11.5)
julia> mquantile(darr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 0.25, 1, 2)
2 x 3 DictArray
a b |a b |a b
-----------+-----------+-----------
11.0 10.0 |11.75 7.75 |12.5 7.75
11.75 7.75 |12.5 7.75 |13.25 7.75
julia> mquantile(larr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 0.25, 2, 1, rev=true)
2 x 3 LabeledArray
|1 |2 |3
--+-----------+-----------+-----------
|a b |a b |a b
--+-----------+-----------+-----------
1 |13.75 7.25 |13.75 6.5 |13.75 5.75
2 |13.75 6.5 |13.75 5.75 |16.0 5.0
source: DataCubes/src/util/array_helper_functions.jl:1461
DataCubes.msum ¶
msum(arr, dims... [; rev=false, window=0]) for arr of type AbstractArrayWrapper/LabeledArray/DictArray.
Calculate moving sum of arr using the last window elements, or cumulative sum if window=0.
Arguments
arr:AbstractArrayWrapper/LabeledArray/DictArray, the input array. When applied toDictArray,msumis applied to each field. When applied toLabeledArray,msumis applied to the base.dims: by defaultdims=(1,). That is, moving sum is performed in the first direction. Ifdims=(n1, n2,...), for each slice spanned along the directionsn1,n2, ..., moving sum is taken along the leading dimension indimsfirst (i.e.sum(dims)), and then the next dimension, and so on.rev: Ifrev=true, moving sum is calculated backward starting for the last elements. By default,rev=false.window: Ifwindow>0, only the lastwindowelements, including the one in consideration, will be used to calculate moving sum. Ifwindow=0,sumcalculates the cumulative sum.NAwill be ignored.
Examples
julia> msum(@nalift([10,11,12,14,17]))
5-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable(10)
Nullable(21)
Nullable(33)
Nullable(47)
Nullable(64)
julia> msum(@nalift([10,NA,12,14,17]))
5-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable(10)
Nullable(10)
Nullable(22)
Nullable(36)
Nullable(53)
julia> msum(darr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 1, 2)
2 x 3 DictArray
a b |a b |a b
------+------+------
11 10 |37 26 |65 40
25 17 |52 32 |81 45
julia> msum(larr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 2, 1, rev=true)
2 x 3 LabeledArray
|1 |2 |3
--+------+------+------
|a b |a b |a b
--+------+------+------
1 |81 45 |56 28 |29 13
2 |70 35 |44 19 |16 5
source: DataCubes/src/util/array_helper_functions.jl:825
DataCubes.nafill ¶
nafill(arr, dims... [; rev=false, window=0]) for arr of type AbstractArrayWrapper/LabeledArray/DictArray.
Fill forward (backward if rev=true) arr using non-null values from the last window elements, or latest non-null value from the beginning if window=0.
Arguments
arr:AbstractArrayWrapper/LabeledArray/DictArray, the input array. When applied toDictArray,nafillis applied to each field. When applied toLabeledArray,nafillis applied to the base.dims: by defaultdims=(1,). That is, the fill forward is performed along the first direction. Ifdims=(n1, n2,...), for each slice spanned along the directionsn1,n2, ..., the fill forward is taken along the leading dimension indimsfirst (i.e.sum(dims)), and then the next dimension, and so on.rev: Ifrev=true, the backward filling is calculated instead, starting for the last elements. By default,rev=false.window: Ifwindow>0, only the lastwindowelements, including the one in consideration, will be used to fill forward. Ifwindow=0,nafillfills forwardarrusing all the elements so far.NAwill be ignored.
Examples
julia> t = @nalift([1 NA;NA 4;NA NA])
3x2 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable{Int64}()
Nullable{Int64}() Nullable(4)
Nullable{Int64}() Nullable{Int64}()
julia> nafill(t)
3x2 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable{Int64}()
Nullable(1) Nullable(4)
Nullable(1) Nullable(4)
julia> nafill(t,2)
3x2 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable(1)
Nullable{Int64}() Nullable(4)
Nullable{Int64}() Nullable{Int64}()
julia> nafill(t,2,1)
3x2 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable(1)
Nullable(1) Nullable(4)
Nullable(1) Nullable(4)
julia> nafill(t, rev=true)
3x2 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable(4)
Nullable{Int64}() Nullable(4)
Nullable{Int64}() Nullable{Int64}()
julia> nafill(t, window=2)
3x2 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable{Int64}()
Nullable(1) Nullable(4)
Nullable{Int64}() Nullable(4)
source: DataCubes/src/util/array_helper_functions.jl:637
DataCubes.nalift ¶
nalift(arr)
Lift each element in an array arr to Nullable if it is not already so.
Unlike @nalift, it does not perform lifting recursively.
It returns arr itself when applied to a DictArray/LabeledArray.
Examples
julia> nalift(Any[[1,2,3],[4,5]])
2-element DataCubes.AbstractArrayWrapper{Nullable{Array{Int64,1}},1,Array{Nullable{Array{Int64,1}},1}}:
Nullable([1,2,3])
Nullable([4,5])
julia> nalift([1,2,3])
3-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable(1)
Nullable(2)
Nullable(3)
julia> nalift(Any[[1,2,3],[4,5]])
2-element DataCubes.AbstractArrayWrapper{Nullable{Array{Int64,1}},1,Array{Nullable{Array{Int64,1}},1}}:
Nullable([1,2,3])
Nullable([4,5])
julia> nalift(darr(a=[1 2;3 4;5 6], b=[:x :y;:z :w;:u :v]))
3 x 2 DictArray
a b |a b
----+----
1 x |2 y
3 z |4 w
5 u |6 v
source: DataCubes/src/na/na.jl:266
DataCubes.namerge ¶
namerge(xs...)
Combine Nullable arrays and Nullable elements, having the later arguments override the preceding ones if the new element is not null.
Arguments
xs... consists of either a AbstractArrayWrapper with Nullable element type, or a Nullable variable. If an element is neither AbstractArray or Nullable, it will be wrapped by Nullable.
Return
- When there is no argument, an error will raise.
- If there is only one argument, that argument will be returned.
- If there are two arguments and if the two are not
AbstractArray, the second argument will be returned only if it is not null. Otherwise, the first argument will be returned. - If there are two arguments, and the two are
Nullablearrays, the element at each position will be the one from the first argument if the second argument element is null. Otherwise, the element from the second argument will be used. If any argument is notAbstractArray, it will be promoted to aNullablearray.
Examples
julia> namerge(10, @nalift([1 2 NA;4 NA NA]))
2x3 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable(2) Nullable(10)
Nullable(4) Nullable(10) Nullable(10)
julia> namerge(@nalift([1 2 NA;4 NA NA]), 10)
2x3 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(10) Nullable(10) Nullable(10)
Nullable(10) Nullable(10) Nullable(10)
julia> namerge(10, @nalift([1 2 NA;4 NA NA]))
2x3 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable(2) Nullable(10)
Nullable(4) Nullable(10) Nullable(10)
julia> namerge(@nalift([1 2 NA;4 NA NA]), @nalift([11 NA NA;14 15 NA]))
2x3 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(11) Nullable(2) Nullable{Int64}()
Nullable(14) Nullable(15) Nullable{Int64}()
source: DataCubes/src/util/array_util.jl:2230
DataCubes.peel ¶
Peel off a variable to see its underlying data.
-
peel(arr::DictArray): returns anLDictconsisting of field name => field values array pairs. -
peel(arr::LabeledArray): returns the underlying data, which can be aDictArraybut can also be anyAbstractArray. -
peel(arr::EnumerationArray): returns the underlying index integers.
Examples
julia> peel(darr(a=[1,2,3], b=[:m,:n,:p]))
DataCubes.LDict{Symbol,DataCubes.AbstractArrayWrapper{T,1,A<:AbstractArray{T,N}}} with 2 entries:
:a => [Nullable(1),Nullable(2),Nullable(3)]
:b => [Nullable(:m),Nullable(:n),Nullable(:p)]
julia> peel(larr(a=[1,2,3], b=[:m,:n,:p], axis1=["X","Y","Z"]))
3 DictArray
a b
----
1 m
2 n
3 p
julia> peel(@enumeration([NA :x :y;:x :z NA]))
2x3 DataCubes.AbstractArrayWrapper{Int64,2,Array{Int64,2}}:
0 1 3
1 2 0
source: DataCubes/src/util/array_util.jl:838
DataCubes.pick ¶
Pick fields from a DictArray or a LabeledArray.
pick(arr::DictArray, fieldname): returns the field value array corresponding tofieldname.pick(arr::DictArray, fieldnames::AbstractArray): returns aDictArraywhose field names arefieldnames.pick(arr::DictArray, fieldnames::Tuple): returns a vector of field value arrays corresponding tofieldnames.pick(arr::DictArray, fieldnames::...)if there are more than 1 field name infieldnames: returns a vector of field value arrays corresponding to thefieldnames.pick(arr::LabeledArray, fieldname): returns the field value array corresponding tofieldname. Iffieldnamecorresponds to a field in an axis, the field value array is broadcast appropriately.pick(arr::LabeledArray, fieldnames::AbstractArray): returns aDictArraywhose field names arefieldnames.pick(arr::LabeledArray, fieldnames::Tuple): returns a vector of field value arrays corresponding tofieldnames.pick(arr::LabeledArray, fieldnames::...)if there are more than 1 field name infieldnames: returns a vector of field value arrays corresponding to thefieldnames.
Examples
julia> pick(darr(a=[1,2,3], b=[:m,:n,:p]), :a)
3-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable(1)
Nullable(2)
Nullable(3)
julia> pick(darr(a=[1,2,3], b=[:m,:n,:p]), (:a,))
1-element Array{DataCubes.AbstractArrayWrapper{T,1,A<:AbstractArray{T,N}},1}:
[Nullable(1),Nullable(2),Nullable(3)]
julia> pick(darr(a=[1,2,3], b=[:m,:n,:p]), :a, :b)
2-element Array{DataCubes.AbstractArrayWrapper{T,1,A<:AbstractArray{T,N}},1}:
[Nullable(1),Nullable(2),Nullable(3)]
[Nullable(:m),Nullable(:n),Nullable(:p)]
julia> pick(darr(a=[1,2,3], b=[:m,:n,:p]), (:a, :b))
2-element Array{DataCubes.AbstractArrayWrapper{T,1,A<:AbstractArray{T,N}},1}:
[Nullable(1),Nullable(2),Nullable(3)]
[Nullable(:m),Nullable(:n),Nullable(:p)]
julia> t = larr(a=[1 2;3 4;5 6], b=[:x :y;:z :u;:v :w], axis1=darr(k=["X","Y","Z"]), axis2=[:A,:B])
3 x 2 LabeledArray
|A |B
--+----+----
k |a b |a b
--+----+----
X |1 x |2 y
Y |3 z |4 u
Z |5 v |6 w
julia> pick(t, :a)
pic3x2 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable(2)
Nullable(3) Nullable(4)
Nullable(5) Nullable(6)
julia> pick(t, :a, :k)
2-element Array{DataCubes.AbstractArrayWrapper{T,N,A<:AbstractArray{T,N}},1}:
3x2 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable(2)
Nullable(3) Nullable(4)
Nullable(5) Nullable(6)
3x2 DataCubes.AbstractArrayWrapper{Nullable{ASCIIString},2,DataCubes.BroadcastAxis{Nullable{ASCIIString},2,DataCubes.AbstractArrayWrapper{Nullable{ASCIIString},1,Array{Nullable{ASCIIString},1}},DataCubes.DictArray{Symbol,2,DataCubes.AbstractArrayWrapper{T,2,A<:AbstractArray{T,N}},Nullable{T}}}}:
Nullable("X") Nullable("X")
Nullable("Y") Nullable("Y")
Nullable("Z") Nullable("Z")
julia> pick(t, (:a, :k))
2-element Array{DataCubes.AbstractArrayWrapper{T,N,A<:AbstractArray{T,N}},1}:
3x2 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable(2)
Nullable(3) Nullable(4)
Nullable(5) Nullable(6)
3x2 DataCubes.AbstractArrayWrapper{Nullable{ASCIIString},2,DataCubes.BroadcastAxis{Nullable{ASCIIString},2,DataCubes.AbstractArrayWrapper{Nullable{ASCIIString},1,Array{Nullable{ASCIIString},1}},DataCubes.DictArray{Symbol,2,DataCubes.AbstractArrayWrapper{T,2,A<:AbstractArray{T,N}},Nullable{T}}}}:
Nullable("X") Nullable("X")
Nullable("Y") Nullable("Y")
Nullable("Z") Nullable("Z")
julia> pick(t, [:a, :k])
3 x 2 DictArray
a k |a k
----+----
1 X |2 X
3 Y |4 Y
5 Z |6 Z
source: DataCubes/src/util/array_util.jl:931
DataCubes.pickaxis ¶
Pick axes from a LabeledArray.
pickaxis(arr::LabeledArray)picks a tuple of axes ofarr.pickaxis(arr::LabeledArray, index::Integer)picks the axis along theindexdirection.pickaxis(arr::LabeledArray, index::Integer, fields...)picks the fieldsfieldsfrom theindexth axis inarr. It is the same aspick(pickaxis(arr, index), fields...).
Examples
julia> t = larr(a=[1 2;3 4;5 6], b=[:x :y;:z :u;:v :w], axis1=darr(k=["X","Y","Z"]), axis2=[:A,:B])
3 x 2 LabeledArray
|A |B
--+----+----
k |a b |a b
--+----+----
X |1 x |2 y
Y |3 z |4 u
Z |5 v |6 w
julia> pickaxis(t)
(3 DictArray
k
--
X
Y
Z
,[Nullable(:A),Nullable(:B)])
julia> pickaxis(t, 1)
3 DictArray
k
--
X
Y
Z
julia> pickaxis(t, 1, :k)
3-element DataCubes.AbstractArrayWrapper{Nullable{ASCIIString},1,Array{Nullable{ASCIIString},1}}:
Nullable("X")
Nullable("Y")
Nullable("Z")
source: DataCubes/src/util/array_util.jl:998
DataCubes.providenames ¶
providenames(arr::LabeledArray, create_fieldname::Funcion)
Add generic field names for fields without field names in a LabeledArray.
This makes the data and all the axes components DictArrays.
This is useful when you want to apply selct/update/leftjoin/innerjoin whose interface is friendlier to DictArrays than general AbstractArrays.
The reverse operation, removing generic field names, is done by withdrawnames.
An optional argument create_fieldname is a function that gives a symbol that will be used as a new field name given an integer index.
By default, it generates :xN for an index integer N.
Examples
julia> t = larr([1 2 3;4 5 6], axis1=[:X,:Y], axis2=darr(k=["A","B","C"]))
2 x 3 LabeledArray
k |A |B |C
--+--+--+--
| | |
--+--+--+--
X |1 |2 |3
Y |4 |5 |6
julia> providenames(t)
2 x 3 LabeledArray
k |A |B |C
---+---+---+---
x2 |x1 |x1 |x1
---+---+---+---
X |1 |2 |3
Y |4 |5 |6
source: DataCubes/src/util/array_util.jl:2062
DataCubes.rename ¶
rename(arr::DictArray, ks...)
Rename the field names so that the first few field names are ks.
Return
A new DictArray whose first few field names are ks.
source: DataCubes/src/datatypes/dict_array.jl:1094
DataCubes.reorder ¶
reorder(arr::DictArray, ks...)
Reorder the field names so that the first few field names are ks.
Return
A new DictArray whose fields are shuffled from arr so that the first few field names are ks.
source: DataCubes/src/datatypes/dict_array.jl:1080
DataCubes.replace_axes ¶
Description
Replace axes with another fields.
The args are a list of pairs of the form (integer for the axis index) => new axes fields for this axis.
Only the first elements (arr[:,...,:,1,:,...,:]) will be taken. That is, if the underlying data array is 2 dimensional, and
you want to use the field column1 as a new key for the 1st axis, column1[:,1] will be used as the new axis.
e.g. replace_axes(labeled_array, 1=>[:c1,:c2], 3=>[:c3])
source: DataCubes/src/util/array_util.jl:342
DataCubes.selct ¶
selct(t, agg... [; by=[...]..., where=[...]...])
Select a LabeledArray or DictArray into another by choosing / grouping / aggregating.
Arguments
Below t' is an object such that t'[k] for a field name k gives the corresponding array
for the field k in the table t at the coordinates selected so far.
t: aLabeledArrayorDictArray.agg...: each argument can be field names, fieldname=>(t'->nullable array function) pair,by[...]orwhere[...]. A fieldname=function can be used instead of the pair notation if the fieldname is a symbol.by=[...]: the firstby=[...]has an array of similar expressions and determines the 1st axis. The secondby=[...]similarly determines the 2nd axis. The outputLabeledArraywill have dimensions of the number ofby[...]clauses, or the original dimensions if noby[...]is provided.where=[...]: has (t'->nullable boolean array) functions inside and chooses the appropriate portion of the original array. Multiplewhere=[...]will simply be combined.
Return
A LabeledArray transformed by args... if t is a LabeledArray.
If t is DictArray and the transformed LabeledArray has DefaultAxis along each direction, the return value is also a DictArray. Otherwise it is a LabeledArray.
Examples
julia> t = @larr(a=1:10, b=[1,2,3,NA,NA,NA,1,1,2,3], c=[:x,:x,:x,:x,:y,:y,:y,:z,:z,:z])
10 LabeledArray
|a b c
---+-------
1 |1 1 x
2 |2 2 x
3 |3 3 x
4 |4 x
5 |5 y
6 |6 y
7 |7 1 y
8 |8 1 z
9 |9 2 z
10 |10 3 z
julia> selct(t, :a, :b=>d->d[:b] .* 2)
10 LabeledArray
|a b
---+-----
1 |1 2
2 |2 4
3 |3 6
4 |4
5 |5
6 |6
7 |7 2
8 |8 2
9 |9 4
10 |10 6
julia> selct(t, :a, :b=>d->d[:b] .* 2, where=[d->d[:c] .!= :z], where=[d->d[:a] .> 2])
5 LabeledArray
|a b
--+----
1 |3 6
2 |4
3 |5
4 |6
5 |7 2
julia> selct(t, a=d->mean(d[:a]), b=d->sum(d[:b] .* 2), by=Any[:d=>d->d[:b] .* 2], by=[:c])
4 x 3 LabeledArray
c |x |y |z
--+------+------+-------
d |a b |a b |a b
--+------+------+-------
|4.0 0 |5.5 0 |
2 |1.0 2 |7.0 2 |8.0 2
4 |2.0 4 | |9.0 4
6 |3.0 6 | |10.0 6
source: DataCubes/src/util/select.jl:816
DataCubes.shift ¶
shift(arr, offsets... [; isbound=false])
Parallel shift the input array arr so that the element at [1,...,1] in arr shows up at [1,...,1]+offsets in the return array.
Arguments
arr:AbstractArrayWrapper/LabeledArray/DictArray, the input array. When applied toDictArray,shiftis applied to each field. When applied toLabeledArray,shiftis applied to the base.offsets: integers to denote the amount of offset for each direction. It is assumed that there is no shift in the missing direcitons.isbound: defaultfalse. Iftrue, the index is floored and capped between 1 and the maximum possible index along that direction. Iffalse, any out of bound index due to shifting results in a nullable element.
Examples
julia> shift(nalift([1 2 3;4 5 6;7 8 9]), 1, 1)
3x3 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(5) Nullable(6) Nullable{Int64}()
Nullable(8) Nullable(9) Nullable{Int64}()
Nullable{Int64}() Nullable{Int64}() Nullable{Int64}()
julia> shift(nalift([1 2 3;4 5 6;7 8 9]), 1, 01)
3x3 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(5) Nullable(6) Nullable{Int64}()
Nullable(8) Nullable(9) Nullable{Int64}()
Nullable{Int64}() Nullable{Int64}() Nullable{Int64}()
julia> shift(nalift([1 2 3;4 5 6;7 8 9]), 1, 1)
3x3 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(5) Nullable(6) Nullable{Int64}()
Nullable(8) Nullable(9) Nullable{Int64}()
Nullable{Int64}() Nullable{Int64}() Nullable{Int64}()
julia> shift(nalift([1 2 3;4 5 6;7 8 9]), 1, -1)
3x3 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable{Int64}() Nullable(4) Nullable(5)
Nullable{Int64}() Nullable(7) Nullable(8)
Nullable{Int64}() Nullable{Int64}() Nullable{Int64}()
julia> shift(darr(a=[1 2 3;4 5 6;7 8 9]), 1, -1)
3 x 3 DictArray
a |a |a
--+--+--
|4 |5
|7 |8
| |
julia> shift(larr(a=[1 2 3;4 5 6;7 8 9], axis2=[:X,:Y,:Z]), 1, -1)
3 x 3 LabeledArray
|X |Y |Z
--+--+--+--
|a |a |a
--+--+--+--
1 | |4 |5
2 | |7 |8
3 | | |
source: DataCubes/src/util/array_helper_functions.jl:1831
DataCubes.tensorprod ¶
tensorprod(arrs...)
Calculate the tensor product of arrs.
tensorprod(::AbstractArray...)calculates the tensor product where the product operation creates a tuple of the input elements at each position, if every input element at that position is notNA. Otherwise, the result will beNA.tensorprod(::DictArray...)calculates the tensor product where the product operation creates a mergedLDictof the inputLDicts at each position.tensorprod(::LabeledArray...)calculates the tensor product of the bases of the inputs, which will be used as the base of the returnLabeledArray. The axes of the return value will be appropriately extended version of the inputs.
Examples
julia> tensorprod(@nalift([1,2,NA]), @nalift([3,NA]))
3x2 DataCubes.AbstractArrayWrapper{Nullable{Tuple{Int64,Int64}},2,Array{Nullable{Tuple{Int64,Int64}},2}}:
Nullable((1,3)) Nullable{Tuple{Int64,Int64}}()
Nullable((2,3)) Nullable{Tuple{Int64,Int64}}()
Nullable{Tuple{Int64,Int64}}() Nullable{Tuple{Int64,Int64}}()
julia> tensorprod(@darr(a=[1,2,NA]), @darr(b=[3,NA]))
3 x 2 DictArray
a b |a b
----+----
1 3 |1
2 3 |2
3 |
julia> tensorprod(@larr(a=[1,2,NA], axis1[:m,:n,:p]), @larr(b=[3,NA], axis1[:X,:Y]))
3 x 2 LabeledArray
|X |Y
--+----+----
|a b |a b
--+----+----
m |1 3 |1
n |2 3 |2
p | 3 |
source: DataCubes/src/util/array_util.jl:1265
DataCubes.ungroup ¶
ungroup(arr, ...)
Ungroup array elements in an array into scalar elements along some direction.
Arguments
arr: an array....can beaxis,indices, orref_field: either an axis index along which to ungroup, a range tuple coordinates of the form(i_1,...,i_k,:,i_{k+1},...,i_n)for some integer i's, or the selected elements ofarrafter applying those types of tuples.
Return
An ungrouped array of the same type as arr. If arr is LabeledArray, the axis along the ungrouping direction will become a new field (a generic field name is provided if it was not a DictArray axis.
Examples
julia> t = larr(a=Any[[1,2,3],[4,5]], b=[:x,:x], c=Any[[11,12,13],[14,15]], axis1=[:X,:Y])
2 LabeledArray
|a b c
--+---------------------
X |[1,2,3] x [11,12,13]
Y |[4,5] x [14,15]
julia> ungroup(t, 1)
5 LabeledArray
|x1 a b c
--+----------
1 |X 1 x 11
2 |X 2 x 12
3 |X 3 x 13
4 |Y 4 x 14
5 |Y 5 x 15
julia> ungroup(t, (:,1))
5 LabeledArray
|x1 a b c
--+----------
1 |X 1 x 11
2 |X 2 x 12
3 |X 3 x 13
4 |Y 4 x 14
5 |Y 5 x 15
julia> m = nalift(reshape(Any[[1,2],[3,4],[5,6,7],[8,9,10]],2,2))
2x2 DataCubes.AbstractArrayWrapper{Nullable{Array{Int64,1}},2,Array{Nullable{Array{Int64,1}},2}}:
Nullable([1,2]) Nullable([5,6,7])
Nullable([3,4]) Nullable([8,9,10])
julia> ungroup(m, 2)
2x5 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable(2) Nullable(5) Nullable(6) Nullable(7)
Nullable(3) Nullable(4) Nullable(8) Nullable(9) Nullable(10)
source: DataCubes/src/util/ungroup.jl:64
DataCubes.update ¶
update(t, agg... [; by=[...]..., where=[...]...])
Similar to selct, but is used to update and create a new LabeledArray or DictArray from the original one.
The main difference from the selct function is that it keeps the original fields intact, unless
directed otherwise, whereas the select macro only chooses the fields that are explicitly specified.
Arguments
Below t' is an object such that t'[k] for a field name k gives the corresponding array
for the field k in the table t at the coordinates selected so far.
t: a LabeledArray orDictArray.agg...: each argument can be field names, fieldname=>(t'->nullable array function) pair,by[...]orwhere[...]. A fieldname=function can be used instead of the pair notation if the fieldname is a symbol.by=[...]:by[...]has (t'->nullable array) as its elements and used as in grouping when updateing. Multipleby[...]are simply combined.where=[...]: has (t'->nullable boolean array) functions inside and chooses the appropriate portion of the original array. Multiplewhere=[...]will simply be combined.
Return
An updated array of the same type as t.
Examples
julia> t = @larr(a=1:10, b=[1,2,3,NA,NA,NA,1,1,2,3], c=[:x,:x,:x,:x,:y,:y,:y,:z,:z,:z])
10 LabeledArray
|a b c
---+-------
1 |1 1 x
2 |2 2 x
3 |3 3 x
4 |4 x
5 |5 y
6 |6 y
7 |7 1 y
8 |8 1 z
9 |9 2 z
10 |10 3 z
julia> update(t, a=d->d[:a] .+ 100, d=d->d[:a] .* d[:b])
10 LabeledArray
|a b c d
---+-----------
1 |101 1 x 1
2 |102 2 x 4
3 |103 3 x 9
4 |104 x
5 |105 y
6 |106 y
7 |107 1 y 7
8 |108 1 z 8
9 |109 2 z 18
10 |110 3 z 30
julia> update(t, a=d->d[:a] .+ 100, d=d->d[:a] .* d[:b], where=[d-> ~isna(d[:b])])
10 LabeledArray
|a b c d
---+-----------
1 |101 1 x 1
2 |102 2 x 4
3 |103 3 x 9
4 |4 x
5 |5 y
6 |6 y
7 |107 1 y 7
8 |108 1 z 8
9 |109 2 z 18
10 |110 3 z 30
julia> update(t, a=d->sum(d[:a]), d=d->reverse(d[:a] .* d[:b]), where=[d-> ~isna(d[:b])], by=[:b])
10 LabeledArray
|a b c d
---+----------
1 |16 1 x 8
2 |11 2 x 18
3 |13 3 x 30
4 |4 x
5 |5 y
6 |6 y
7 |16 1 y 7
8 |16 1 z 1
9 |11 2 z 4
10 |13 3 z 9
source: DataCubes/src/util/select.jl:1035
DataCubes.withdrawnames ¶
withdrawnames(arr::LabeledArray, check_fieldname::Function)
Remove generic field names from a LabeledArray if possible.
Arguments
arris an inputLabeledArray.check_fieldnameis a function that returns whether an input field name is a generic name. By default, a field name is generic if it is a symbol of the form:xNfor some integerN.
Return
If a field name in LabeledArray gives true when applied to check_fieldname, and the field name can be removed, it is removed in the return LabeledArray. A field name can be removed if it is a part of a DictArray with only one field.
Examples
julia> t = larr([1 2 3;4 5 6], axis1=[:X,:Y], axis2=darr(k=["A","B","C"]))
2 x 3 LabeledArray
k |A |B |C
--+--+--+--
| | |
--+--+--+--
X |1 |2 |3
Y |4 |5 |6
julia> providenames(t)
2 x 3 LabeledArray
k |A |B |C
---+---+---+---
x2 |x1 |x1 |x1
---+---+---+---
X |1 |2 |3
Y |4 |5 |6
julia> withdrawnames(providenames(t))
2 x 3 LabeledArray
k |A |B |C
--+--+--+--
| | |
--+--+--+--
X |1 |2 |3
Y |4 |5 |6
source: DataCubes/src/util/array_util.jl:2134
rename(arr::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}, ks...) ¶
rename(arr::LabeledArray, ks...)
Rename the field names of the base of arr so that the first few field names are ks.
Return
A new LabeledArray whose first few field names of the base of arr are ks.
source: DataCubes/src/datatypes/labeled_array.jl:1317
rename(ldict::DataCubes.LDict{K, V}, ks...) ¶
rename(ldict::LDict, ks...)
Renames the first few keys using ks.
Examples
julia> rename(LDict(:a=>1, :b=>2, :c=>3), :b, 'x')
DataCubes.LDict{Any,Int64} with 3 entries:
:b => 1
'x' => 2
:c => 3
source: DataCubes/src/datatypes/ldict.jl:290
reorder(arr::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}, ks...) ¶
reorder(arr::LabeledArray, ks...)
Reorder the field names of the base of arr so that the first few field names are ks.
The base of arr is expected to be a DictArray.
Return
A new LabeledArray whose base fields are shuffled from arr so that the first few field names are ks.
source: DataCubes/src/datatypes/labeled_array.jl:1305
reorder(ldict::DataCubes.LDict{K, V}, ks...) ¶
reorder(ldict::LDict, ks...)
Reorder the keys so that the first few keys are ks.
Examples
julia> reorder(LDict(:a=>1, :b=>2, :c=>3), :b, :c)
DataCubes.LDict{Symbol,Int64} with 3 entries:
:b => 2
:c => 3
:a => 1
source: DataCubes/src/datatypes/ldict.jl:271
replace_axes(arr::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}, args...) ¶
replace_axes(arr::LabeledArray, args...)
Arguments
arr: an inputLabeledArray. Note the data part ofarrand the axis to replace need to beDictArrays.args...: arguments inargsare of the formi=>[f1,f2,...]for some integeriand field namesf*.
Returns
For each i=>[f1,f2,...] in args, the ith axis is replaced by the fields f1, f2, ....
A nonarray value in i=>f1 will be automatically promoted to an array with one element: [f1].
If the key i is omitted, the smallest relevant axis number will be automatically assigned.
Only the first elements will be taken. For example, if the underlying data array is 2 dimensional, and if you want to use some field for the 1st axis, [:,1] components will be used.
The original axis becomes the data part of LabeledArray after properly broadcast.
If the field name array is null for an argument in args (i=>[]), the corresponding axis will be DefaultAxis.
Examples
julia> t = larr(a=[1 2 3;4 5 6], b=['a' 'b' 'c';'d' 'e' 'f'], axis1=darr(k=[:x,:y]), axis2=["A","B","C"])
2 x 3 LabeledArray
|A |B |C
--+----+----+----
k |a b |a b |a b
--+----+----+----
x |1 a |2 b |3 c
y |4 d |5 e |6 f
julia> replace_axes(t, 1=>[:a]) # == replace_axes(t, [:a]) == replace_axes(t, :a)
2 x 3 LabeledArray
|A |B |C
--+----+----+----
a |b k |b k |b k
--+----+----+----
1 |a x |b x |c x
4 |d y |e y |f y
julia> replace_axes(t, 1=>[:a, :b])
2 x 3 LabeledArray
|A |B |C
----+--+--+--
a b |k |k |k
----+--+--+--
1 a |x |x |x
4 d |y |y |y
source: DataCubes/src/util/array_util.jl:398
DataCubes.DictArray{K, N, VS, SV} ¶
A multidimensional array whose elements are ordered dictionaries with common keys.
Internally, it is represented as an ordered dictionary from keys to multidimensional arrays.
Note that most functions return a new DictArray rather than modify the existing one.
However, the new DictArray just shallow copies the key vector and the value vector
of the underlying LDict. Therefore, creating a new DictArray is cheap, but you have to be
careful when you modify the underlying array elements directly.
Because a DictArray can be multidimensional we will call the keys in the key vector of the underlying LDict the field names.
The values in the value vector will be called fields. With a slight bit of abuse of notation, we sometimes call a field name and a field tuple collectively just a field.
Use the function darr to construct a DictArray.
Constructors
DictArraay is internally just a wrapper of LDict. Therefore, the constructors takes the same kind of arguments:
DictArray(data::LDict{K,V})
DictArray{K,V}(dict::Dict{K,V})
DictArray{K,V}(dict::Dict{K,V}, ks)
DictArray{K}(ks::Vector{K}, vs::Vector)
DictArray(ps::Pair...)
DictArray(tuples::Tuple...)
DictArray(;kwargs...)
source: DataCubes/src/datatypes/dict_array.jl:31
DataCubes.EnumerationArray{T, N, V, R<:Integer} ¶
An array type to store elements that have only a few choices.
That is, it is a pooled array.
Use enumeration to create an EnumerationArray.
source: DataCubes/src/datatypes/enumeration_array.jl:8
DataCubes.LDict{K, V} ¶
LDict is an ordered dictionary. It is assumed to be used in the field name => field mapping. In practice, the number of columns is not that long, and it is more efficient to implement LDict as 2 vectors, one for keys and one for values.
Constructors
LDict{K,V}(dict::Associative{K, V}) # LDict from a dictionary dict. The result order is undetermined.
LDict{K,V}(dict::Associative{K, V}, ks) # LDict from a dictionary dict. ks is a vector of keys, and the keys in the result are ordered in that way. An error is thrown if one of ks is not found in dict.
LDict{K,V}(ks::Vector{K}, vs::Vector{V})
LDict(ps::Pair...)
LDict(ps::Tuple...)
source: DataCubes/src/datatypes/ldict.jl:18
DataCubes.LabeledArray{T, N, AXES<:Tuple, TN} ¶
A multidimensional array together with additional axes attached to it.
Each axis is a one dimensional array, possibly a DictArray.
Use the function larr or a macro version @larr to create LabeledArrays, rather than call the constructor directly.
A LabeledArray consists of one main array, which we call the base array, and an axis array for each direction.
Constructors
LabeledArray(arr, axes)creates aLabeledArrayfrom a base arrayarrand a tupleaxesof one dimensional arrays for axes.LabeledArray(arr; kwargs...)creates aLabeledArrayfrom a base arrayarrand a keyword argument of the formaxisN=Vfor some integerNfor the axis direction and a one dimensional arrayV. IfNinaxisNis omitted, the smallest available number is automatically chosen.
source: DataCubes/src/datatypes/labeled_array.jl:16
@darr(args...) ¶
@darr(...)
Create a DictArray. The arguments ... can be one of the following:
Arguments
k=>vcreates a field using an arrayvwith field namek.kcan be an arbitrary type. If the element type ofvis notNullable, each element will be wrapped byNullable. IfNAis provided as an element, it is translated asNullable{T}()for an appropriate typeT.k=vcreates a field using an arrayvwith field name:k.- There can be at most one non pair type argument, which will be converted into a
DictArrayand other pair arguments will update it.
Examples
julia> t = @darr(a=[1 2;NA 4;5 NA],b=["abc" NA;1 2;:m "xyz"],:c=>[NA 1.5;:sym 'a';"X" "Y"])
3 x 2 DictArray
a b c |a b c
----------+----------
1 abc |2 1.5
1 sym |4 2 a
5 m X | xyz Y
julia> @darr(t, c=[1 2;3 4;5 6], "d"=>map(Nullable, [1 2;3 4;5 6]))
3 x 2 DictArray
a b c d |a b c d
----------+----------
1 abc 1 1 |2 2 2
1 3 3 |4 2 4 4
5 m 5 5 | xyz 6 6
source: DataCubes/src/datatypes/dict_array.jl:1135
@enumeration(args...) ¶
@enumeration(arr [, poolorder])
Create an EnumerationArray. Similar to the enumeration function, but you can type in a null element using NA.
Arguments
arr: an input array ofNullableelement type. It is assumed that there are only a few possible values inarrand each value is converted into an integer when creating anEnumerationArray.NAis translated into a null element of appropriate type.poolorder: a vector to fix some of the integer values in the mapping from the values inarrto integers. If there arenelements inpoolorder, thosenelements inarrwill be assigned 1...nwhen creating anEnumerationArray. All the others are assigned integers in order of their appearance.
Examples
julia> @enumeration([:A,:A,:B,NA,NA])
5-element DataCubes.EnumerationArray{Symbol,1,DataCubes.AbstractArrayWrapper{Int64,1,Array{Int64,1}},Int64}:
Nullable(:A)
Nullable(:A)
Nullable(:B)
Nullable{Symbol}()
Nullable{Symbol}()
julia> @enumeration([:A,:A,:B,NA,NA]).pool
2-element Array{Symbol,1}:
:A
:B
julia> @enumeration([:A,:A,:B,NA,NA]).elems
5-element DataCubes.AbstractArrayWrapper{Int64,1,Array{Int64,1}}:
1
1
2
0
0
julia> @enumeration([:A,:A,:B,NA,NA], [:B,:A])
5-element DataCubes.EnumerationArray{Symbol,1,DataCubes.AbstractArrayWrapper{Int64,1,Array{Int64,1}},Int64}:
Nullable(:A)
Nullable(:A)
Nullable(:B)
Nullable{Symbol}()
Nullable{Symbol}()
julia> @enumeration([:A,:A,:B,NA,NA], [:B,:A]).pool
2-element Array{Symbol,1}:
:B
:A
julia> @enumeration([:A,:A,:B,NA,NA], [:B,:A]).elems
5-element DataCubes.AbstractArrayWrapper{Int64,1,Array{Int64,1}}:
2
2
1
0
0
source: DataCubes/src/datatypes/enumeration_array.jl:271
@larr(args...) ¶
@larr(...)
Create a LabeledArray. The arguments ... can be one of the following:
Arguments
k=>vcreates a field using arrayvwith field namekfor the base of the returnLabeledArray.kcan be an arbitrary type. If the element type ofvis notNullable, each element will be wrapped byNullable. IfNAis provided as an element, it is translated asNullable{T}()for an appropriate typeT.k=vcreates a field using arrayvof the base with field name:k.- There can be at most one non pair type argument, which will be converted into a
LabeledArrayand other pair arguments will update it. axisN[...]for some integerN: this creates an axis along theNth direction. If...are either keywords or pairs, those are used to create aDictArray. Otherwise, an array will be created using.... IfNinaxisNis omitted, the smallest available number is automatically chosen.
Examples
julia> t = @larr(a=[1 NA;3 4;NA NA],:b=>[1.0 1.5;:sym 'a';"X" "Y"],c=1,axis1[:U,NA,:W],axis[r=['m','n']])
3 x 2 LabeledArray
r |m |n
--+--------+--------
|a b c |a b c
--+--------+--------
U |1 1.0 1 | 1.5 1
|3 sym 1 |4 a 1
W | X 1 | Y 1
julia> @larr(t, c=[NA NA;3 4;5 6], :d=>:X, axis1[k=["g","h","i"]])
3 x 2 LabeledArray
r |m |n
--+----------+----------
k |a b c d |a b c d
--+----------+----------
g |1 1.0 X | 1.5 X
h |3 sym 3 X |4 a 4 X
i | X 5 X | Y 6 X
source: DataCubes/src/datatypes/labeled_array.jl:1360
@nalift(expr) ¶
@nalift(arr)
Lift each element in an array arr to Nullable if it is not already so.
It is mainly used to translate a manually typed array expression such as [1,2,3,NA,5] into a Nullable array.
Unlike nalift, it performs lifting recursively.
It returns arr itself when applied to a DictArray/LabeledArray.
Examples
julia> @nalift([1,2,3])
3-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable(1)
Nullable(2)
Nullable(3)
julia> @nalift([1,2,NA])
3-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable(1)
Nullable(2)
Nullable{Int64}()
julia> @nalift(Any[[1,2,3],[NA,5]])
2-element DataCubes.AbstractArrayWrapper{Nullable{DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}},1,Array{Nullable{DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}},1}}:
Nullable([Nullable(1),Nullable(2),Nullable(3)])
Nullable([Nullable{Int64}(),Nullable(5)])
julia> @nalift(larr(a=[1 2;3 4;5 6], b=[:x :y;:z :w;:u :v]))
3 x 2 LabeledArray
|1 |2
--+----+----
|a b |a b
--+----+----
1 |1 x |2 y
2 |3 z |4 w
3 |5 u |6 v
source: DataCubes/src/na/na.jl:377
@rap(args...) ¶
@rap(args...)
Apply right-to-left evaluation order to the arguments.
An argument having an underscore symbol except the last one is translated into the function x->(that expression replacing _ by x).
Examples
julia> @rap _+3 5
8
julia> @rap _*2 x->x+1 10
22
julia> @rap (_ .* 2) reverse @nalift [1,2,NA,4,5]
5-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable(10)
Nullable(8)
Nullable{Int64}()
Nullable(4)
Nullable(2)
source: DataCubes/src/util/array_util.jl:271
@select(t, args...) ¶
@select(t, args...)
Select macro transforms a LabeledArray or DictArray into another by choosing / grouping / aggregating.
Arguments
Below t' is an object such that t'[k] for a field name k gives the corresponding array
for the field k in the table t at the coordinates selected so far.
t: aLabeledArrayorDictArray.args...: each argument can be field names, fieldname=>(t'->nullable array function) pair,by[...]orwhere[...]. A fieldname=function can be used instead of the pair notation if the fieldname is a symbol. The firstby[...]has an array of similar expressions and determines the 1st axis. The secondby[...]similarly determines the 2nd axis. The outputLabeledArraywill have dimensions of the number ofby[...]clauses, or the original dimensions if noby[...]is provided.where[...]has (t'->nullable boolean array) functions inside and chooses the appropriate portion of the original array. Multiplewhere[...]will simply be combined.
Function Specification
Note that a function (t'->nullable array) is expressed by some expression with variable names with underscores. The expression is converted into `t''->expression. Symbols with underscores are converted in the following way:
_k: translates tot'[k]. The field namekshould be a symbol._!k: translates toisna(t')[k]. It gives a boolean array to denote whether an element is null. The field namekshould be a symbol._: translates tot'if none of the above is applicable. It is useful when the field name is not a symbol.
Return
A LabeledArray transformed by args... if t is a LabeledArray.
If t is DictArray and the transformed LabeledArray has DefaultAxis along each direction, the return value is also a DictArray. Otherwise it is a LabeledArray.
Examples
julia> t = @larr(a=1:10, b=[1,2,3,NA,NA,NA,1,1,2,3], c=[:x,:x,:x,:x,:y,:y,:y,:z,:z,:z])
10 LabeledArray
|a b c
---+-------
1 |1 1 x
2 |2 2 x
3 |3 3 x
4 |4 x
5 |5 y
6 |6 y
7 |7 1 y
8 |8 1 z
9 |9 2 z
10 |10 3 z
julia> @select(t, :a, :b=>_b .* 2)
10 LabeledArray
|a b
---+-----
1 |1 2
2 |2 4
3 |3 6
4 |4
5 |5
6 |6
7 |7 2
8 |8 2
9 |9 4
10 |10 6
julia> @select(t, :a, :b=>_b .* 2, where[_c .!= :z], where[_a .> 2])
5 LabeledArray
|a b
--+----
1 |3 6
2 |4
3 |5
4 |6
5 |7 2
julia> @select(t, a=mean(_a), b=sum(_b .* 2), by[d=_b .* 2], by[:c])
4 x 3 LabeledArray
c |x |y |z
--+------+------+-------
d |a b |a b |a b
--+------+------+-------
|4.0 0 |5.5 0 |
2 |1.0 2 |7.0 2 |8.0 2
4 |2.0 4 | |9.0 4
6 |3.0 6 | |10.0 6
source: DataCubes/src/util/select.jl:727
@update(t, args...) ¶
@update(t, args...)
Similar to select macro, but is used to update and create a new LabeledArray or DictArray from the original one.
The main difference from the select macro is that it keeps the original fields intact, unless
directed otherwise, whereas the select macro only chooses the fields that are explicitly specified.
Arguments
Below t' is an object such that t'[k] for a field name k gives the corresponding array
for the field k in the table t at the coordinates selected so far.
t: aLabeledArrayorDictArray.args...: each argument can be field names, fieldname=>(t'->nullable array function) pair orwhere[...]. A fieldname=function can be used instead of the pair notation if the fieldname is a symbol.by[...]has (t'->nullable array) as its elements and used as in grouping when updateing. Multipleby[...]are simply combined.where[...]has (t'->nullable boolean array) functions inside and chooses the appropriate portion of the original array. Multiplewhere[...]will simply be combined.
Function Specification
Note that a function (t'->nullable array) is expressed by some expression with variable names with underscores. The expression is converted into `t''->expression. Symbols with underscores are converted in the following way:
_k: translates tot'[k]. The field namekshould be a symbol._!k: translates toisna(t')[k]. It gives a boolean array to denote whether an element is null. The field namekshould be a symbol._: translates tot'if none of the above is applicable. It is useful when the field name is not a symbol.
Return
An updated array of the same type as t.
Examples
julia> t = @larr(a=1:10, b=[1,2,3,NA,NA,NA,1,1,2,3], c=[:x,:x,:x,:x,:y,:y,:y,:z,:z,:z])
10 LabeledArray
|a b c
---+-------
1 |1 1 x
2 |2 2 x
3 |3 3 x
4 |4 x
5 |5 y
6 |6 y
7 |7 1 y
8 |8 1 z
9 |9 2 z
10 |10 3 z
julia> @update(t, a=_a .+ 100, d=_a .* _b)
10 LabeledArray
|a b c d
---+-----------
1 |101 1 x 1
2 |102 2 x 4
3 |103 3 x 9
4 |104 x
5 |105 y
6 |106 y
7 |107 1 y 7
8 |108 1 z 8
9 |109 2 z 18
10 |110 3 z 30
julia> @update(t, a=_a .+ 100, d=_a .* _b, where[~isna(_b)])
10 LabeledArray
|a b c d
---+-----------
1 |101 1 x 1
2 |102 2 x 4
3 |103 3 x 9
4 |4 x
5 |5 y
6 |6 y
7 |107 1 y 7
8 |108 1 z 8
9 |109 2 z 18
10 |110 3 z 30
julia> @update(t, a=sum(_a), d=reverse(_a .* _b), where[~isna(_b)], by[:b])
10 LabeledArray
|a b c d
---+----------
1 |16 1 x 8
2 |11 2 x 18
3 |13 3 x 30
4 |4 x
5 |5 y
6 |6 y
7 |16 1 y 7
8 |16 1 z 1
9 |11 2 z 4
10 |13 3 z 9
source: DataCubes/src/util/select.jl:936
Internal
DataCubes.create_dict ¶
create_dict(::LabeledArray)
Create a nested Dict from a LabeledArray.
Examples
julia> t = larr(a=[1 2;3 4], axis1=[:x,:y], axis2=["A","B"])
2 x 2 LabeledArray
| |A B
--+--+----
x |a |1 2
--+--+----
y |a |3 4
julia> create_dict(t)
Dict{Nullable{Symbol},Dict{Nullable{ASCIIString},DataCubes.LDict{Symbol,Nullable{Int64}}}} with 2 entries:
Nullable(:y) => Dict(Nullable("B")=>DataCubes.LDict(:a=>Nullable(4)),Nullable("A")=>DataCubes.LDict(:a=>Nullable(3)))
Nullable(:x) => Dict(Nullable("B")=>DataCubes.LDict(:a=>Nullable(2)),Nullable("A")=>DataCubes.LDict(:a=>Nullable(1)))
source: DataCubes/src/datatypes/labeled_array.jl:1124
DataCubes.gdrop ¶
gdrop(arr, N1, N2, ...)
Drop a block of an array. similar to drop in one dimensional case, but is slightly different and more general.
It can also be applied to an LDict.
It drops the first N1 elements along direction 1, and similarly for other directions. Drops from rear if N* is negative.
Examples
julia> t = larr(a=rand(5,3), b=reshape(1:15,5,3), axis1=[:X,:Y,:Z,:U,:V])
5 x 3 LabeledArray
|1 |2 |3
--+----------------------+-----------------------+-----------------------
|a b |a b |a b
--+----------------------+-----------------------+-----------------------
X |0.27289790581491746 1 |0.8493197848353495 6 |0.8370920536703472 11
Y |0.8424940964507834 2 |0.21518951524950136 7 |0.9290437789813346 12
Z |0.9498541774517255 3 |0.942687447396005 8 |0.1341678643795654 13
U |0.7356663426240728 4 |0.7662948222160162 9 |0.24109069576951692 14
V |0.8716491751450759 5 |0.27472373001295436 10 |0.08909928028262804 15
julia> gdrop(t, 3, 2)
2 x 1 LabeledArray
|1
--+-----------------------
|a b
--+-----------------------
U |0.24109069576951692 14
V |0.08909928028262804 15
julia> gdrop(t, 5)
0 x 3 LabeledArray
|1 |2 |3
-+----+----+----
|a b |a b |a b
julia> gdrop(t, -3, -2)
2 x 1 LabeledArray
|1
--+----------------------
|a b
--+----------------------
X |0.27289790581491746 1
Y |0.8424940964507834 2
source: DataCubes/src/util/array_util.jl:1581
DataCubes.gtake ¶
gtake(arr, N1, N2, ...)
Take a block of an array. similar to take in one dimensional case, but is slightly different and more general.
It can also be applied to an LDict.
It takes first N1 elements along direction 1, and similarly for other directions. Repeats if the number of elements are less than N*. Picks from rear if N* is negative.
Examples
julia> t = larr(a=rand(5,3), b=reshape(1:15,5,3), axis1=[:X,:Y,:Z,:U,:V])
5 x 3 LabeledArray
|1 |2 |3
--+----------------------+-----------------------+-----------------------
|a b |a b |a b
--+----------------------+-----------------------+-----------------------
X |0.3219487839233375 1 |0.4863723989946185 6 |0.8784616074632225 11
Y |0.04069063166302023 2 |0.06614308437642014 7 |0.31870618693881947 12
Z |0.7855545407740521 3 |0.5208010912357377 8 |0.4421485355996708 13
U |0.8134241459627629 4 |0.8256022894268482 9 |0.3127049127123851 14
V |0.8536688845922342 5 |0.7263660648355621 10 |0.9315379228053462 15
julia> gtake(t, 3, 2)
3 x 2 LabeledArray
|1 |2
--+----------------------+----------------------
|a b |a b
--+----------------------+----------------------
X |0.3219487839233375 1 |0.4863723989946185 6
Y |0.04069063166302023 2 |0.06614308437642014 7
Z |0.7855545407740521 3 |0.5208010912357377 8
julia> gtake(t, 3, 4)
3 x 4 LabeledArray
|1 |2 |3 |4
--+----------------------+----------------------+-----------------------+----------------------
|a b |a b |a b |a b
--+----------------------+----------------------+-----------------------+----------------------
X |0.3219487839233375 1 |0.4863723989946185 6 |0.8784616074632225 11 |0.3219487839233375 1
Y |0.04069063166302023 2 |0.06614308437642014 7 |0.31870618693881947 12 |0.04069063166302023 2
Z |0.7855545407740521 3 |0.5208010912357377 8 |0.4421485355996708 13 |0.7855545407740521 3
julia> gtake(t, -2, -1)
2 x 1 LabeledArray
|1
--+----------------------
|a b
--+----------------------
U |0.3127049127123851 14
V |0.9315379228053462 15
source: DataCubes/src/util/array_util.jl:1370
DataCubes.selectfield ¶
selectfield(t, fld, inds) : select a field whose name is fld at cartesian coordinates inds in a LabeledArray t.
If inds is nothing, it chooses an entire fld from t.
source: DataCubes/src/util/select.jl:495
DataCubes.setna! ¶
setna!(arr, args...)
Set the element of an array arr at args to NA.
If args... is omitted, all elements are set to NA.
- If
arris an array of element typeNullable{T},NAmeansNullable{T}(). - If
arris aDictArray,NAmeans all fields at that position areNA. - If
arris aLabeledArray,NAmeans the base ofarrat that position isNA.
Examples
julia> setna!(@nalift([1,2,NA,4,5]))
5-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable{Int64}()
Nullable{Int64}()
Nullable{Int64}()
Nullable{Int64}()
Nullable{Int64}()
julia> setna!(@nalift([1,2,NA,4,5]), 2)
5-element Array{Nullable{Int64},1}:
Nullable(1)
Nullable{Int64}()
Nullable{Int64}()
Nullable(4)
Nullable(5)
julia> setna!(@darr(a=[1 2 NA;4 5 6], b=[:x :y :z;:u :v :w]), 1:2, 1)
2 x 3 DictArray
a b |a b |a b
----+----+----
|2 y | z
|5 v |6 w
julia> setna!(larr(a=[1 2 3;4 5 6], b=[:x :y :z;:u :v :w], axis1=[:X,:Y]), 1, 2:3)
2 x 3 LabeledArray
|1 |2 |3
--+----+----+----
|a b |a b |a b
--+----+----+----
X |1 x | |
Y |4 u |5 v |6 w
source: DataCubes/src/na/na.jl:457
DataCubes.type_array ¶
type_array(arr)
type_array finds the most constraining type of the elements of an array arr, and converts the array element type.
Sometimes, an array is given type Array{Any}, even though the components are all Float64, for example.
type_array will convert the type into the most constraining one.
Arguments
arr::AbstractArray: an abstract array whose element type will be constrained bytype_array.
Returns
An array with the same elements as in arr, but the element type has been constrained just enough to contain all elements.
Examples
julia> type_array(Any[1, 3.0, 2])
3-element Array{Float64,1}:
1.0
3.0
2.0
julia> type_array(Any[1, 3.0, 'x'])
3-element Array{Any,1}:
1
3.0
'x'
source: DataCubes/src/util/array_util.jl:34
diff ¶
diff(arr, dims... [; rev=false]) for arr of type AbstractArrayWrapper/LabeledArray/DictArray.
Take the difference between adjacent elements of arr along the directions belonging to the integers dims.
Note that diff applied to AbstractArrayWrapper (or to LabeledArray or DictArray by extension) will have the same shape as the original array. The first elements will be the first elements of the input array. This will ensure cumsum(diff(arr)) == diff(cumsum(arr)) == arr if there is no Nullable element.
Arguments
arr:AbstractArrayWrapper/LabeledArray/DictArray, the input array. When applied toDictArray,diffis applied to each field. When applied toLabeledArray,diffis applied to the base.dims: by defaultdims=(1,). That is, difference is calculated along the first direction. Ifdims=(n1, n2,...), for each slice spanned along the directionsn1,n2, ..., difference is taken along the leading dimension indimsfirst (i.e.sum(dims)), and then the next dimension, and so on.rev: Ifrev=true, difference is taken backward starting for the last elements. By default,rev=false.
Examples
julia> diff(@nalift([10,NA,12,14,17]))
5-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable(10)
Nullable{Int64}()
Nullable{Int64}()
Nullable(2)
Nullable(3)
julia> diff(darr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 1, 2)
2 x 3 DictArray
a b |a b |a b
------+------+------
11 10 |-2 2 |-2 2
3 -3 |3 -3 |3 -3
julia> diff(darr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 1, 2, rev=true)
2 x 3 DictArray
a b |a b |a b
------+------+-----
-3 3 |-3 3 |-3 3
2 -2 |2 -2 |16 5
julia> diff(larr(a=[11 12 13;14 15 16], b=[10 9 8;7 6 5]), 1, 2, rev=true)
2 x 3 LabeledArray
|1 |2 |3
--+------+------+-----
|a b |a b |a b
--+------+------+-----
1 |-3 3 |-3 3 |-3 3
2 |2 -2 |2 -2 |16 5
source: DataCubes/src/util/array_helper_functions.jl:745
allfieldnames(arr::DataCubes.DictArray{K, N, VS, SV}) ¶
allfieldnames(::DictArray)
Return all field names in the input DictArray, which are just the keys in the underlying LDict.
Examples
julia> allfieldnames(darr(a=reshape(1:6,3,2),b=rand(3,2)))
2-element Array{Symbol,1}:
:a
:b
source: DataCubes/src/datatypes/dict_array.jl:542
allfieldnames(table::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}) ¶
returns all field names for LabeledArray or DictArray. Returns an empty array for other types of arrays.
source: DataCubes/src/datatypes/labeled_array.jl:842
cat(catdim::Integer, arr1::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}, arrs::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}...) ¶
cat(catdim::Integer, arrs::LabeledArray...)
Concatenate LabeledArrays arrs along the catdim direction.
The base of each element of arrs are concatenated and become the new base of the return LabeledArray.
The axes of each of arrs not along the catdim direction should be identical. Otherwise, there will be an error.
The axis along the catdim direction will be the concatenation of the axis of each of arrs along that direction.
julia> t1 = larr(a=[1 2 3;4 5 6], axis1=[:x,:y], axis2=["A","B","C"])
t2 x 3 LabeledArray
| |A B C
--+--+------
x |a |1 2 3
--+--+------
y |a |4 5 6
julia> t2 = larr(a=[11 12 13;14 15 16], axis1=[:x,:y], axis2=["D","E","F"])
2 x 3 LabeledArray
| |D E F
--+--+---------
x |a |11 12 13
--+--+---------
y |a |14 15 16
julia> cat(2, t1, t2)
2 x 6 LabeledArray
| |A B C D E F
--+--+---------------
x |a |1 2 3 11 12 13
--+--+---------------
y |a |4 5 6 14 15 16
source: DataCubes/src/datatypes/labeled_array.jl:893
cat(catdim::Integer, arrs::DataCubes.DictArray{K, N, VS, SV}...) ¶
cat(catdim::Integer, arrs::DictArray...)
Concatenate the DictArrays arrs along the catdim direction.
The common fields are concatenated field by field.
If a field name does not exist in all of arrs, a null field with that field name will be added to those DictArrays with that missing field name, and then the arrays will be concatenated field by field.
Examples
julia> cat(1, darr(a=[1 2 3], b=[:x :y :z]),
darr(c=[3 2 1], b=[:m :n :p]))
2 x 3 DictArray
a b c |a b c |a b c
------+------+------
1 x |2 y |3 z
m 3 | n 2 | p 1
julia> cat(2, darr(a=[1 2 3], b=[:x :y :z]),
darr(c=[3 2 1], b=[:m :n :p]))
1 x 6 DictArray
a b c |a b c |a b c |a b c |a b c |a b c
------+------+------+------+------+------
1 x |2 y |3 z | m 3 | n 2 | p 1
source: DataCubes/src/datatypes/dict_array.jl:632
convert(::Type{DataCubes.DictArray{K, N, VS, SV}}, df::DataFrames.DataFrame) ¶
convert(::Type{DictArray}, df::DataFrame) converts a DataFrame into DictArray.
source: DataCubes/src/interface/dataframe_interface.jl:84
convert(::Type{DataCubes.EnumerationArray{T, N, V, R<:Integer}}, arr::DataArrays.PooledDataArray{T, R<:Integer, N}) ¶
convert(::Type{EnumerationArray}, arr::PooledDataArray) converts a PooledDataArray into an EnumerationArray.
source: DataCubes/src/interface/dataframe_interface.jl:112
convert(::Type{DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}}, df::DataFrames.DataFrame) ¶
convert(::Type{LabeledArray}, df::DataFrame) converts a DataFrame into LabeledArray simply by wrapping convert(DictArray, df) by LabeledArray.
source: DataCubes/src/interface/dataframe_interface.jl:91
convert(::Type{DataFrames.DataFrame}, arr::DataCubes.DictArray{K, N, VS, SV}) ¶
convert(::Type{DataFrame}, arr::DictArray) converts a DictArray into a DataFrame. If the dimensions of arr are greater than 1, arr is first flattend into 1 dimension using collapse_axes, and then converted into a DataFrame.
source: DataCubes/src/interface/dataframe_interface.jl:98
convert(::Type{DataFrames.DataFrame}, arr::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}) ¶
convert(::Type{DataFrame}, arr::LabeledArray) converts a LabeledArray into a DataFrame by first creating a DictArray by broadcasting all axes, and then convert that DictArray into a DataFrame.
source: DataCubes/src/interface/dataframe_interface.jl:105
deletekeys{K, V}(dict::DataCubes.LDict{K, V}, keys...) ¶
deletekeys(dict::LDict, keys...)
Delete keys keys from dict. A missing key will be silently ignored.
julia> deletekeys(LDict(:a=>3, :b=>5, :c=>10), :a, :b, :x)
DataCubes.LDict{Symbol,Int64} with 1 entry:
:c => 10
source: DataCubes/src/datatypes/ldict.jl:152
dropnaiter{T, N}(arr::AbstractArray{Nullable{T}, N}) ¶
dropnaiter(arr)
Generate an iterator from a nullable array arr, which iterates over only non-null elements.
Examples
julia> for x in dropnaiter(@nalift([1,2,NA,4,5]))
println(x)
end
1
2
4
5
source: DataCubes/src/util/array_helper_functions.jl:24
enum_dropnaiter{T, N}(arr::AbstractArray{Nullable{T}, N}) ¶
enum_dropnaiter(arr)
Generate an iterator from a nullable array arr, which yields (index, elem) for an integer index for non-null element positions of arr and a non-null element elem.
Examples
julia> for x in enum_dropnaiter(@nalift([:A,:B,NA,NA,:C]))
println(x)
end
(1,:A)
(2,:B)
(5,:C)
source: DataCubes/src/util/array_helper_functions.jl:44
fill(ldict::DataCubes.LDict{K, V}, dims::Integer...) ¶
fill(ldict::LDict, dims...)
Fill a DictArray with ldict.
Return
A new DictArray whose elements are ldict and whose dimensions are dims....
source: DataCubes/src/datatypes/dict_array.jl:1067
flipdim(arr::DataCubes.DictArray{K, N, VS, SV}, dims::Integer...) ¶
flipdim(arr::DictArray, dims...)
Flip a DictArray arr using an iterable variable dims. The same method as reverse(arr::DictArray, dims).
Arguments
arris an inputDictArray.dimsis an iterable variable ofInts.
Return
A DictArray whose elements along any directions belonging to dims are fliped.
Examples
julia> t = darr(a=[1 2 3;4 5 6], b=[:x :y :z;:u :v :w])
2 x 3 DictArray
a b |a b |a b
----+----+----
1 x |2 y |3 z
4 u |5 v |6 w
julia> flipdim(t, 1)
2 x 3 DictArray
a b |a b |a b
----+----+----
4 u |5 v |6 w
1 x |2 y |3 z
julia> flipdim(t, 1, 2)
2 x 3 DictArray
a b |a b |a b
----+----+----
6 w |5 v |4 u
3 z |2 y |1 x
source: DataCubes/src/datatypes/dict_array.jl:1055
getindexvalue(arr::AbstractArray{T, N}, args...) ¶
getindexvalue(arr::AbstractArray, args...)
Return arr[args...].
source: DataCubes/src/datatypes/dict_array.jl:194
getindexvalue(arr::DataCubes.DictArray{K, N, VS, SV}, args...) ¶
getindexvalue(arr::DictArray, args...)
Return the value tuple of arr at index args.
source: DataCubes/src/datatypes/dict_array.jl:182
intersect(dim::Integer, arr0::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}, arr_rest::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}...) ¶
intersect(dim, arrs...)
Take intersection of arrays of type LabeledArray/DictArray/AbstractArrayWrapper. The order is preserved.
Arguments
dim: direction along which to intersect.arrs...: arrays to intersect.
Examples
julia> intersect(1, nalift([1 2 3;4 5 6]), nalift([1 2 3;5 5 6]))
1x3 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable(2) Nullable(3)
julia> intersect(2, nalift([1 2 3;4 5 6]), nalift([1 2 3;5 5 6]))
2x2 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(2) Nullable(3)
Nullable(5) Nullable(6)
julia> intersect(1, darr(a=[:x,:y,:z]), darr(a=[:x,:x,:y]), darr(a=[:y,:y,:y]))
1 DictArray
a
--
y
julia> intersect(1, larr(a=[1 2 3;4 5 6], axis1=[:X,:Y]), larr(a=[1 2 3;4 3 2], axis1=[:X,:Y]))
1 x 3 LabeledArray
|1 |2 |3
--+--+--+--
|a |a |a
--+--+--+--
X |1 |2 |3
julia> intersect(1, larr(a=[1 2 3;4 5 6], axis1=[:X,:Y]), larr(a=[1 2 3;4 3 2], axis1=[:Z,:Y]))
0 x 3 LabeledArray
|1 |2 |3
-+--+--+--
|a |a |a
source: DataCubes/src/util/intersect.jl:53
keys(arr::DataCubes.DictArray{K, N, VS, SV}) ¶
keys(::DictArray)
Return the field name vector of the input DictArray, which are the keys of the underlying LDict.
Examples
julia> keys(darr(a=[1,2,3], b=[:x,:y,:z]))
2-element Array{Symbol,1}:
:a
:b
source: DataCubes/src/datatypes/dict_array.jl:927
map(f::Function, arr::DataCubes.DictArray{K, N, VS, SV}) ¶
map(f::Function, arr::DictArray)
Apply the function f to each element of arr.
f will take an LDict and produces a value of type, say T.
The return value will have the same size as arr and its elements have type T.
If the return element type T is not nullable, the result elements are wrapped by Nullable.
If the return element type T is LDict, the result will be again a DictArray.
However, in this case, the LDict should be of the type LDict{K,Nullable{V}}.
Examples
julia> map(x->x[:a].value + x[:b].value, darr(a=[1 2;3 4], b=[1.0 2.0;3.0 4.0]))
2x2 DataCubes.AbstractArrayWrapper{Nullable{Float64},2,DataCubes.FloatNAArray{Float64,2,Array{Float64,2}}}:
Nullable(2.0) Nullable(4.0)
Nullable(6.0) Nullable(8.0)
julia> map(x->LDict(:c=>Nullable(x[:a].value + x[:b].value)), darr(a=[1 2;3 4], b=[1.0 2.0;3.0 4.0]))
2 x 2 DictArray
c |c
----+----
2.0 |4.0
6.0 |8.0
source: DataCubes/src/datatypes/dict_array.jl:741
mapslices(f::Function, arr::DataCubes.DictArray{K, N, VS, SV}, dims::AbstractArray{T, 1}) ¶
mapslices(f::Function, arr::DictArray, dims)
Apply the function f to each slice of arr specified by dims. dims is a vector of integers along which direction to reduce.
- If
dimsincludes all dimensions,fwill be applied to the wholearr. - If
dimsis empty,mapslicesis the same asmap. - Otherwise,
fis applied to each slice spanned by the directions.
Return
Return a dimensionally reduced array along the directions in dims.
If the return value of f is an LDict, the return value of the corresponding mapslices is a DictArray.
If the return valud of f is an AbstractArray, the return value of the corresponding mapslices will be an array of the same type, but the dimensions have been extended. If the original dimensions are N1 x N2 x ... x Nn and f returns an array of dimensions M1 x ... x Mm, the return array will be of dimensions M1 x ... x Mm x N1 x ... x Nn with those Nis omitted that belong to dims. You can think of this as the usual mapslices, followed by cat. See the last two examples below.
Otherwise, the return value is an Array.
julia> mapslices(d->d[:a] .* 2, darr(a=[1 2 3;4 5 6], b=[10 11 12;13 14 15]), [1])
3-element DataCubes.AbstractArrayWrapper{Nullable{DataCubes.AbstractArrayWrapper{Nullable{Int64},1,DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}}},1,Array{Nullable{DataCubes.AbstractArrayWrapper{Nullable{Int64},1,DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}}},1}}:
Nullable([Nullable(2),Nullable(8)])
Nullable([Nullable(4),Nullable(10)])
Nullable([Nullable(6),Nullable(12)])
julia> mapslices(d->d[:a] .* 2, darr(a=[1 2 3;4 5 6], b=[10 11 12;13 14 15]), [2])
2-element DataCubes.AbstractArrayWrapper{Nullable{DataCubes.AbstractArrayWrapper{Nullable{Int64},1,DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}}},1,Array{Nullable{DataCubes.AbstractArrayWrapper{Nullable{Int64},1,DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}}},1}}:
Nullable([Nullable(2),Nullable(4),Nullable(6)])
Nullable([Nullable(8),Nullable(10),Nullable(12)])
julia> mapslices(d->LDict(:c=>sum(d[:a]), :d=>sum(d[:b] .* 3)), darr(a=[1 2 3;4 5 6], b=[10 11 12;13 14 15]), [2])
2 DictArray
c d
-------
6 99
15 126
julia> mapslices(x->msum(x), darr(a=reshape(1:15,5,3), b=1.0*reshape(1:15,5,3)), [1])
reseltype = DataCubes.DictArray{Symbol,1,DataCubes.AbstractArrayWrapper{T,1,A<:AbstractArray{T,N}},Nullable{T}}
5 x 3 DictArray
a b |a b |a b
--------+--------+--------
1 1.0 |6 6.0 |11 11.0
3 3.0 |13 13.0 |23 23.0
6 6.0 |21 21.0 |36 36.0
10 10.0 |30 30.0 |50 50.0
15 15.0 |40 40.0 |65 65.0
# note how the order of axes changed. the newly generated directions always preced the existing ones.
julia> mapslices(x->msum(x), darr(a=reshape(1:15,5,3), b=1.0*reshape(1:15,5,3)), [2])
reseltype = DataCubes.DictArray{Symbol,1,DataCubes.AbstractArrayWrapper{T,1,A<:AbstractArray{T,N}},Nullable{T}}
3 x 5 DictArray
a b |a b |a b |a b |a b
--------+--------+--------+--------+--------
1 1.0 |2 2.0 |3 3.0 |4 4.0 |5 5.0
7 7.0 |9 9.0 |11 11.0 |13 13.0 |15 15.0
18 18.0 |21 21.0 |24 24.0 |27 27.0 |30 30.0
source: DataCubes/src/datatypes/dict_array.jl:846
mapslices(f::Function, arr::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}, dims::AbstractArray{T, 1}) ¶
mapslices(f::Function, arr::LabeledArray, dims)
Apply the function f to each slice of arr specified by dims. dims is a vector of integers along which direction to reduce.
- If
dimsincludes all dimensions,fwill be applied to the wholearr. - If
dimsis empty,mapslicesis the same asmap. - Otherwise,
fis applied to each slice spanned by the directions.
Return
Return a dimensionally reduced array along the directions in dims.
If the return value of f is an LDict, the return value of the corresponding mapslices is a DictArray.
If the return valud of f is an AbstractArray, the return value of the corresponding mapslices will be an array of the same type, but the dimensions have been extended. If the original dimensions are N1 x N2 x ... x Nn and f returns an array of dimensions M1 x ... x Mm, the return array will be of dimensions M1 x ... x Mm x N1 x ... x Nn with those Nis omitted that belong to dims. You can think of this as the usual mapslices, followed by cat. See the last two examples below.
Otherwise, the return value is an Array.
julia> mapslices(d->d[:a] .* 2,larr(a=[1 2 3;4 5 6],b=[10 11 12;13 14 15],axis1=darr(k=[:X,:Y]),axis2=['A','B','C']),[1])
3 LabeledArray
|
--+---------------------------
A |[Nullable(2),Nullable(8)]
B |[Nullable(4),Nullable(10)]
C |[Nullable(6),Nullable(12)]
julia> mapslices(d->d[:a] .* 2,larr(a=[1 2 3;4 5 6],b=[10 11 12;13 14 15],axis1=darr(k=[:X,:Y]),axis2=['A','B','C']),[2])
2 LabeledArray
k |
--+----------------------------------------
X |[Nullable(2),Nullable(4),Nullable(6)]
Y |[Nullable(8),Nullable(10),Nullable(12)]
# note how the order of axes changed. the newly generated directions always preced the existing ones.
julia> mapslices(x->msum(x), larr(axis1=[:A,:B,:C,:D,:E],axis2=['X','Y','Z'],a=reshape(1:15,5,3), b=1.0*reshape(1:15,5,3)), [2])
3 x 5 LabeledArray
|A |B |C |D |E
--+--------+--------+--------+--------+--------
|a b |a b |a b |a b |a b
--+--------+--------+--------+--------+--------
X |1 1.0 |2 2.0 |3 3.0 |4 4.0 |5 5.0
Y |7 7.0 |9 9.0 |11 11.0 |13 13.0 |15 15.0
Z |18 18.0 |21 21.0 |24 24.0 |27 27.0 |30 30.0
source: DataCubes/src/datatypes/labeled_array.jl:1092
merge(arr1::DataCubes.DictArray{K, N, VS, SV}, args...) ¶
merge(::DictArray, args...)
Construct a DictArray using args..., and merges the two DictArrays together.
Example
julia> merge(darr(a=[1,2,3], b=[4,5,6]), b=[:x,:y,:z], :c=>["A","B","C"])
3 DictArray
a b c
------
1 x A
2 y B
3 z C
source: DataCubes/src/datatypes/dict_array.jl:345
merge(arr1::DataCubes.DictArray{K, N, VS, SV}, arr2::DataCubes.DictArray{K, N, VS, SV}) ¶
merge(::DictArray, ::DictArray)`
Merge the two DictArrays. A duplicate field in the second DictArray will override that in the first one. Otherwise, the new field in the second DictArray will be appened after the first DictArray fields.
If the first is DictArray and the remaining arguments are used to construct a DictArray and then the two are merged.
Example
julia> merge(darr(a=[1,2,3], b=[4,5,6]), darr(b=[:x,:y,:z], c=["A","B","C"]))
3 DictArray
a b c
------
1 x A
2 y B
3 z C
source: DataCubes/src/datatypes/dict_array.jl:324
merge(arr1::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}, arr2::DataCubes.DictArray{K, N, VS, SV}) ¶
merge(::LabeledArray, ::DictArray...)
merge(::LabeledArray, args...)
Merge the base of the LabeledArray and either the rest DictArrays, or a DictArray created by args....
Together with the axes set of the input LabeledArray, return a new LabeledArray.
Examples
julia> merge(larr(a=[1,2,3],b=[:x,:y,:z],axis1=[:a,:b,:c]),darr(c=[4,5,6],b=[:m,:n,:p]),darr(a=["X","Y","Z"]))
3 LabeledArray
|a b c
--+------
a |X m 4
b |Y n 5
c |Z p 6
source: DataCubes/src/datatypes/labeled_array.jl:1599
merge(arr1::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}, arr2::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}) ¶
merge(::LabeledArray, ::LabeledArray)
Merge two LabeledArrays. The axes set of the two should be identical.
The bases are merged together and the common axes set is used.
Examples
julia> merge(larr(a=[1,2,3],b=[:x,:y,:z],axis1=[:a,:b,:c]),larr(c=[4,5,6],b=[:m,:n,:p],axis1=[:a,:b,:c]))
3 LabeledArray
|a b c
--+------
a |1 m 4
b |2 n 5
c |3 p 6
source: DataCubes/src/datatypes/labeled_array.jl:1568
merge(dict::DataCubes.LDict{K, V}, ds::Associative{K, V}...) ¶
merge(dict::LDict, ds...)
Combine an LDict dict with Associative ds's.
The subsequent elements in ds will either update the preceding one, or append the key-value pair.
Examples
julia> merge(LDict(:a=>3, :b=>5), Dict(:b=>"X", :c=>"Y"), LDict(:c=>'x', 'd'=>'y'))
DataCubes.LDict{Any,Any} with 4 entries:
:a => 3
:b => "X"
:c => 'x'
'd' => 'y'
source: DataCubes/src/datatypes/ldict.jl:95
reducedim(f::Function, arr::DataCubes.DictArray{K, N, VS, SV}, dims, initial) ¶
reducedim(f::Function, arr::DictArray, dims [, initial])
Reduce a two argument function f along dimensions of arr. dims is a vector specifying the dimensions to reduce, and initial is the initial value to use in the reduction.
- If
dimsincludes all dimensions,reducewill be applied to the wholearrwith initial valueinitial. - Otherwise,
reduceis applied with the functionfto each slice spanned by the directions with initial valueinitial.initialcan be omitted if the underlyingreducedoes not require it.
julia> reducedim((acc,d)->acc+d[:a].value, darr(a=[1 2 3;4 5 6]), [1], 0)
3-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable(5)
Nullable(7)
Nullable(9)
julia> reducedim((acc,d)->acc+d[:a].value, darr(a=[1 2 3;4 5 6]), [2], 0)
2-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable(6)
Nullable(15)
julia> reducedim((acc,d)->acc+d[:a].value, darr(a=[1 2 3;4 5 6]), [1,2], 0)
Nullable(21)
source: DataCubes/src/datatypes/dict_array.jl:770
repeat(arr::DataCubes.DictArray{K, N, VS, SV}) ¶
repeat(arr::DictArray [; inner=..., outer=...])
Apply repeat field by field to the DictArray arr.
source: DataCubes/src/datatypes/dict_array.jl:659
replace_expr(expr) ¶
replace_expr(expr)
Create a function expression from a domain expression.
Expressions
Below t' is an object such that t'[k] for a field name k gives the corresponding array for the field k in the table t at the coordinates selected so far.
_k: translates tot'[k]. The field namekshould be a symbol.__k: translates toigna(t')[k]. It ignores the null elements. The null elements are replaced with arbitrary values, so make sure there is no null value in the array if you want to use it. The field namekshould be a symbol._!k: translates toisna(t')[k]. It gives a boolean array to denote whether an element is null. The field namekshould be a symbol._: translates tot'if none of the above is applicable. It is useful when the field name is not a symbol.
source: DataCubes/src/util/select.jl:1111
reshape(arr::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}, dims::Int64...) ¶
reshape(arr::LabeledArray, dims...)
Reshape arr into different sizes, if there is no ambiguity.
This means you can collapse several contiguous directions into one direction,
in which case all axes belonging to collapsing direction will be concatenated.
For other case, sometimes it is possible to disambiguate the axis position.
But in general, the result is either an error or an undetermined result
as long as the axis positions are concerned.
Examples
julia> t = larr(a=[1 2 3;4 5 6], axis1=[:x,:y], axis2=["A","B","C"])
2 x 3 LabeledArray
|A |B |C
--+--+--+--
|a |a |a
--+--+--+--
x |1 |2 |3
y |4 |5 |6
1 x 6 LabeledArray
x1 |x |y |x |y |x |y
x2 |A |A |B |B |C |C
---+--+--+--+--+--+--
|a |a |a |a |a |a
---+--+--+--+--+--+--
1 |1 |4 |2 |5 |3 |6
julia> reshape(t, 6, 1)
6 x 1 LabeledArray
|1
------+--
x1 x2 |a
------+--
x A |1
y A |4
x B |2
y B |5
x C |3
y C |6
julia> reshape(t, 6)
6 LabeledArray
x1 x2 |a
------+--
x A |1
y A |4
x B |2
y B |5
x C |3
y C |6
julia> reshape(t, 3,2)
ERROR: ArgumentError: dims (3,2) are inconsistent.
source: DataCubes/src/datatypes/labeled_array.jl:1238
reverse(arr::DataCubes.DictArray{K, N, VS, SV}, dims) ¶
reverse(arr::DictArray, dims)
Reverse a DictArray arr using an iterable variable dims.
Arguments
arris an inputDictArray.dimsis an iterable variable ofInts.
Return
A DictArray whose elements along any directions belonging to dims are reversed.
Examples
julia> t = darr(a=[1 2 3;4 5 6], b=[:x :y :z;:u :v :w])
2 x 3 DictArray
a b |a b |a b
----+----+----
1 x |2 y |3 z
4 u |5 v |6 w
julia> reverse(t, [1])
2 x 3 DictArray
a b |a b |a b
----+----+----
4 u |5 v |6 w
1 x |2 y |3 z
julia> reverse(t, 1:2)
2 x 3 DictArray
a b |a b |a b
----+----+----
6 w |5 v |4 u
3 z |2 y |1 x
source: DataCubes/src/datatypes/dict_array.jl:998
sel(func, t) ¶
sel(func, t [; c=[], b=[], a=[]])
an intermediate select/update function to connect selectfunc/updatefunc and @select(selct)/@update(update).
Arguments
Below t' is an object such that t'[k] for a field name k gives the corresponding array
for the field k in the table t at the coordinates selected so far.
func : selectfunc or updatefunc.
t : a LabeledArray.
c : an array of conditions of type t' -> nullable boolean array.
b : an array of arrays of pairs from field names to by functions specified as t' -> a nullable array.
* a : an array of pairs from field names to aggregate functions specified as t' -> a nullable array.
source: DataCubes/src/util/select.jl:590
selectfunc{N}(t::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}, c, b, a) ¶
selectfunc(t::LabeledArray, c, b, a)
main select function. This function is internal and is meant to be used via selct.
selectfunc takes a table t, condition c, aggreagtion by rule b, aggregate function a.
- t : a LabeledArray
- c : an array of functions
(t, inds)-> boolean array.tis a LabeledArray and inds is eithernothingto choose the entiretor an array of Cartesian indices. - b : an array of arrays of pairs of field name => function
(t, inds)-> array.tis a LabeledArray and inds is eithernothingto choose the entiretor an array of Cartesian indices. - c : an array of pairs of field name => function
(t, inds)-> array.tis a LabeledArray and inds is eithernothingto choose the entiretor an array of Cartesian indices.
source: DataCubes/src/util/select.jl:34
selectkeys{K, V}(dict::DataCubes.LDict{K, V}, keys...) ¶
selectkeys(dict::LDict, keys...)
Select keys keys from dict. A missing key will raise an error.
Examples
julia> selectkeys(LDict(:a=>3, :b=>5, :c=>10), :a, :b)
DataCubes.LDict{Symbol,Int64} with 2 entries:
:a => 3
:b => 5
source: DataCubes/src/datatypes/ldict.jl:183
set_default_dispsize!() ¶
set_default_dispsize!()
Set the display height and width limit function to be the default one.
This is used to set the display limits when displaying a DictArray or a LabeledArray.
source: DataCubes/src/datatypes/labeled_array.jl:236
set_default_showsize!() ¶
set_default_showsize!()
Set the show height and width limit function to be the default one.
The default version calculates the height and width based on the current console screen size.
This is used to set the print limits when showing a DictArray or a LabeledArray.
source: DataCubes/src/datatypes/labeled_array.jl:152
set_dispalongrow!(alongrow::Bool) ¶
set_dispalongrow!(alongrow::Bool)
Determine how to display the fields of a DictArray.
By default (alongrow is true), the fields are displayed from left to right.
If alongrow=false, the fields are displayed from top to bottom.
See set_showalongrow! to see an analogous example when showing a DictArray.
source: DataCubes/src/datatypes/labeled_array.jl:280
set_dispheight!(height::Integer) ¶
set_dispheight!(height::Integer)
Set the display height limit to the constant height.
To get to the default behavior, use set_default_dispsize!().
source: DataCubes/src/datatypes/labeled_array.jl:257
set_dispsize!(height::Integer, width::Integer) ¶
set_dispsize!(height::Integer, width::Integer)
Set the display height and width limits to be the constant height and width, respectively.
To get to the default behavior, use set_default_dispsize!().
source: DataCubes/src/datatypes/labeled_array.jl:247
set_dispwidth!(width::Integer) ¶
set_dispwidth!(width::Integer)
Set the display width limit to the constant width.
To get to the default behavior, use set_default_dispsize!().
source: DataCubes/src/datatypes/labeled_array.jl:267
set_format_string!{T}(::Type{T}, fmt::AbstractString) ¶
set_format_string!(T, format_string)
Set the formatting string for type T to format_string.
By default, Float64 is displayed with the type format string "%0.8g", and this is the only one.
julia> @larr(a=rand(3,5),b=rand(1.0*1:10,3,5))
3 x 5 LabeledArray
|1 |2 |3 |4 |5
--+--------------+---------------+--------------+---------------+--------------
|a b |a b |a b |a b |a b
--+--------------+---------------+--------------+---------------+--------------
1 |0.47740705 6 |0.29141232 10 |0.83865594 8 |0.99285171 10 |0.70529279 2
2 |0.39800798 4 |0.32770802 2 |0.6787478 3 |0.74177887 2 |0.19838391 9
3 |0.73599273 7 |0.53117299 4 |0.97372752 8 |0.58885829 4 |0.30529039 8
julia> DataCubes.set_format_string!(Float64, "%0.2f")
"%0.2f"
julia> @larr(a=rand(3,5),b=rand(1.0*1:10,3,5))
3 x 5 LabeledArray
|1 |2 |3 |4 |5
--+----------+----------+----------+-----------+----------
|a b |a b |a b |a b |a b
--+----------+----------+----------+-----------+----------
1 |0.27 6.00 |0.29 7.00 |0.23 1.00 |0.68 2.00 |0.45 7.00
2 |0.95 6.00 |0.71 5.00 |0.61 1.00 |0.64 10.00 |0.10 7.00
3 |0.05 5.00 |0.52 7.00 |0.11 8.00 |0.52 6.00 |0.21 2.00
source: DataCubes/src/datatypes/labeled_array.jl:138
set_showalongrow!(alongrow::Bool) ¶
set_showalongrow!(alongrow::Bool)
Determine how to show the fields of a DictArray.
By default (alongrow is true), the fields are shown from left to right.
If alongrow=false, the fields are shown from top to bottom.
Examples
julia> set_showalongrow!(true)
true
julia> darr(a=[1 2 3;4 5 6], b=[:x :y :z;:u :v :w])
2 x 3 DictArray
a b |a b |a b
----+----+----
1 x |2 y |3 z
4 u |5 v |6 w
julia> set_showalongrow!(false)
false
julia> darr(a=[1 2 3;4 5 6], b=[:x :y :z;:u :v :w])
2 x 3 DictArray
a |1 2 3
b |x y z
--+------
a |4 5 6
b |u v w
source: DataCubes/src/datatypes/labeled_array.jl:223
set_showheight!(height::Integer) ¶
set_showheight!(height::Integer)
Set the show height limit to the constant height.
To get to the default behavior of adjusting to the current console screen size, use set_default_showsize!().
source: DataCubes/src/datatypes/labeled_array.jl:173
set_showsize!(height::Integer, width::Integer) ¶
set_showsize!(height::Integer, width::Integer)
Set the show height and width limits to be the constant height and width, respectively.
To get to the default behavior of adjusting to the current console screen size, use set_default_showsize!().
source: DataCubes/src/datatypes/labeled_array.jl:163
set_showwidth!(width::Integer) ¶
set_showwidth!(width::Integer)
Set the show width limit to the constant width.
To get to the default behavior of adjusting to the current console screen size, use set_default_showsize!().
source: DataCubes/src/datatypes/labeled_array.jl:183
show{N}(io::IO, arr::DataCubes.DictArray{K, N, VS, SV}) ¶
show(io::IO, arr::DictArray [; height::Int=..., width::Int=..., alongorow::Bool=true])
Show a DictArray in io in a square box of given height and width. If not provided, the current terminal's size is used to get the default height and weight. alongrow determines whether to display field names along row or columns.
Examples
julia> show(STDOUT, darr(a=[1,2,3], b=[:x,:y,:z]))
3 DictArray
a b
----
1 x
2 y
3 z
julia> show(STDOUT, darr(a=[1,2,3], b=[:x,:y,:z]), alongrow=false)
3 DictArray
a |1
b |x
--+--
a |2
b |y
--+--
a |3
b |z
source: DataCubes/src/datatypes/dict_array.jl:383
show{N}(io::IO, arr::DataCubes.DictArray{K, N, VS, SV}, indent) ¶
show(io::IO, arr::DictArray [; height::Int=..., width::Int=..., alongorow::Bool=true])
Show a DictArray in io in a square box of given height and width. If not provided, the current terminal's size is used to get the default height and weight. alongrow determines whether to display field names along row or columns.
Examples
julia> show(STDOUT, darr(a=[1,2,3], b=[:x,:y,:z]))
3 DictArray
a b
----
1 x
2 y
3 z
julia> show(STDOUT, darr(a=[1,2,3], b=[:x,:y,:z]), alongrow=false)
3 DictArray
a |1
b |x
--+--
a |2
b |y
--+--
a |3
b |z
source: DataCubes/src/datatypes/dict_array.jl:383
show{N}(io::IO, table::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}) ¶
show(io::IO, table::LabeledArray [, indent=0; height=..., width=...])
Show a LabeledArray.
Arguments
heightandwidth(optional, default set by show_size()): sets the maximum height and width to draw, beyond which the table will be cut.alongrow(optional, default set byset_dispalongrow!.truby default): iftrue, the fields in the array will be displayed along the row in each cell. Otherwise, they will be stacked on top of each other.
source: DataCubes/src/datatypes/labeled_array.jl:294
show{N}(io::IO, table::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}, indent) ¶
show(io::IO, table::LabeledArray [, indent=0; height=..., width=...])
Show a LabeledArray.
Arguments
heightandwidth(optional, default set by show_size()): sets the maximum height and width to draw, beyond which the table will be cut.alongrow(optional, default set byset_dispalongrow!.truby default): iftrue, the fields in the array will be displayed along the row in each cell. Otherwise, they will be stacked on top of each other.
source: DataCubes/src/datatypes/labeled_array.jl:294
sort(arr::Union{DataCubes.DictArray{K, N, VS, SV}, DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}}, axis::Integer, fields...) ¶
sort(arr, axis, fields... [; alg=..., ...])
Sort a DictArray or LabeledArray along some axis.
Arguments
arr: either aDictArrayor aLabeledArray.axis: an axis direction integer to denote which direction to sort along. If omitted, axis=1.fields...: the names of fields to determine the order. The preceding ones have precedence over the later ones. Note only the components [1,...,1,:,1,...1], where : is placed at the axis position, will be used out of each field. If omitted, all fields will be used in their order forDictArrayand the axis along theaxisdirection forLabeledArray.- optionally,
alg=algorithmdetermines the sorting algorithm.fieldname_lt=ltfuncsets the less-than function for the field fieldname, and similarly forby/rev/ord.
Examples
julia> t = larr(a=[3 3 2;7 5 3], b=[:b :a :c;:d :e :f], axis1=["X","Y"])
2 x 3 LabeledArray
|1 |2 |3
--+----+----+----
|a b |a b |a b
--+----+----+----
X |3 b |3 a |2 c
Y |7 d |5 e |3 f
julia> sort(t, 1, :a)
2 x 3 LabeledArray
|1 |2 |3
--+----+----+----
|a b |a b |a b
--+----+----+----
X |3 b |3 a |2 c
Y |7 d |5 e |3 f
julia> sort(t, 2, :a)
2 x 3 LabeledArray
|1 |2 |3
--+----+----+----
|a b |a b |a b
--+----+----+----
X |2 c |3 b |3 a
Y |3 f |7 d |5 e
julia> sort(t, 2, :a, :b)
2 x 3 LabeledArray
|1 |2 |3
--+----+----+----
|a b |a b |a b
--+----+----+----
X |2 c |3 a |3 b
Y |3 f |5 e |7 d
julia> sort(t, 2, :a, :b, a_rev=true)
2 x 3 LabeledArray
|1 |2 |3
--+----+----+----
|a b |a b |a b
--+----+----+----
X |3 a |3 b |2 c
Y |5 e |7 d |3 f
source: DataCubes/src/util/sort.jl:141
unique{T}(arr::DataCubes.AbstractArrayWrapper{Nullable{T}, N, A<:AbstractArray{T, N}}) ¶
unique(arr, dims...)
Return unique elements of an array arr of type LabeledArray/DictArray/Nullable AbstractArrayWrapper.
Arguments
arr: an arraydims...: either an integer or, if an array is a DictArray or a LabeledArray, a list of integers. It specifies the directions along which to traverse. Any duplicate elements will be replaced by Nullable{T}(). If all components along some direction are missing, those components will be removed and the whole array size will shrink. Ifdims...is missing, unique elements along the whole directions will be found. It is equivalent tounique(arr, 1, 2, ..., ndims(arr)). Note that it compares each slice spanned by directions orthogonal todims....
Examples
julia> unique(nalift([1 2 3;3 4 1]))
2x2 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable(2)
Nullable(3) Nullable(4)
julia> unique(nalift([1 2 3;3 4 1]), 1)
2x3 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable(2) Nullable(3)
Nullable(3) Nullable(4) Nullable(1)
julia> unique(nalift([1 2 3;3 4 1]), 2)
2x3 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable(2) Nullable(3)
Nullable(3) Nullable(4) Nullable(1)
julia> unique(nalift([1 2 3;1 2 3;4 5 6]), 1)
2x3 DataCubes.AbstractArrayWrapper{Nullable{Int64},2,Array{Nullable{Int64},2}}:
Nullable(1) Nullable(2) Nullable(3)
Nullable(4) Nullable(5) Nullable(6)
julia> t = darr(a=[1 2 1;1 5 1;1 2 1], b=[:a :b :a;:a :c :a;:a :b :a])
3 x 3 DictArray
a b |a b |a b
----+----+----
1 a |2 b |1 a
1 a |5 c |1 a
1 a |2 b |1 a
julia> unique(t, 1)
2 x 3 DictArray
a b |a b |a b
----+----+----
1 a |2 b |1 a
1 a |5 c |1 a
julia> unique(t, 2)
3 x 2 DictArray
a b |a b
----+----
1 a |2 b
1 a |5 c
1 a |2 b
julia> m = larr(a=[1 2 1;1 5 1;1 2 1], b=[:a :b :a;:a :c :a;:a :b :a], axis1=["X","Y","Z"])
3 x 3 LabeledArray
|1 |2 |3
--+----+----+----
|a b |a b |a b
--+----+----+----
X |1 a |2 b |1 a
Y |1 a |5 c |1 a
Z |1 a |2 b |1 a
julia> unique(m, 1)
2 x 3 LabeledArray
|1 |2 |3
--+----+----+----
|a b |a b |a b
--+----+----+----
X |1 a |2 b |1 a
Y |1 a |5 c |1 a
julia> unique(m, 2)
3 x 2 LabeledArray
|1 |2
--+----+----
|a b |a b
--+----+----
X |1 a |2 b
Y |1 a |5 c
Z |1 a |2 b
source: DataCubes/src/util/unique.jl:102
updatefunc{N}(t::DataCubes.LabeledArray{T, N, AXES<:Tuple, TN}, c, b, a) ¶
updatefunc(t::LabeledArray, c, b, a)
main update function. This function is internal and is meant to be used via update.
updatefunc takes a table t, condition c, aggreagtion by rule b, aggregate function a.
t: a LabeledArrayc: an array of functions(t, inds)-> boolean array.tis a LabeledArray and inds is eithernothingto choose the entiretor an array of Cartesian indices.b: an array of arrays of pairs of field name => function(t, inds)-> array.tis a LabeledArray and inds is eithernothingto choose the entiretor an array of Cartesian indices.c: an array of pairs of field name => function(t, inds)-> array.tis a LabeledArray and inds is eithernothingto choose the entiretor an array of Cartesian indices.
source: DataCubes/src/util/select.jl:142
values(arr::DataCubes.DictArray{K, N, VS, SV}) ¶
values(::DictArray)
Return the vector of field arrays of the input DictArray, which are the values of the underlying LDict.
Examples
julia> values(darr(a=[1,2,3], b=[:x,:y,:z]))
2-element Array{DataCubes.AbstractArrayWrapper{T,1,A<:AbstractArray{T,N}},1}:
[Nullable(1),Nullable(2),Nullable(3)]
[Nullable(:x),Nullable(:y),Nullable(:z)]
source: DataCubes/src/datatypes/dict_array.jl:945
wrap_array(arr::DataCubes.AbstractArrayWrapper{T, N, A<:AbstractArray{T, N}}) ¶
wrap_array(arr)
Wrap an array by AbstractArrayWrapper if it is not DictArray or labeledArray, and not already AbstractArrayWrapper.
source: DataCubes/src/na/naarray_operators.jl:14
zip_dropnaiter{N}(arrs::AbstractArray{T, N}...) ¶
zip_dropnaiter(arrs...)
Generate a zipped iterator from nullable arrays arrs.... If any element in arrs... is null, the iterator will skip it and move to the next element tuple.
Examples
julia> for x in zip_dropnaiter(@nalift([11,12,NA,NA,15]),
@nalift([:X,NA,:Z,NA,:V]),
@nalift([71,72,73,NA,75]))
println(x)
end
(11,:X,71)
(15,:V,75)
source: DataCubes/src/util/array_helper_functions.jl:132
DataCubes.AbstractArrayWrapper{T, N, A<:AbstractArray{T, N}} ¶
A thin wrapper around AbstractArray. The reason to introduce this wrapper is to redefine the dotted operators such as .+, .-. Those operators will be mapped to arrays, elementwise just as before, but, if each element is null, those operators will be applied to the one inside the Nullable. For example,
julia> AbstractArrayWrapper([Nullable(1), Nullable(2)]) .+ AbstractArrayWrapper([Nullable{Int}(), Nullable(3)])
2-element DataCubes.AbstractArrayWrapper{Nullable{Int64},1,Array{Nullable{Int64},1}}:
Nullable{Int64}()
Nullable(5)
Note that this means lifting those dotted operators via the list(AbstractArray) and maybe(Nullable) functors.
It is possible to redefine those operators for AbstractArray, but concerning about compatibility, it may be best to introduce a new wrapper class for that.
source: DataCubes/src/na/na.jl:25
DataCubes.DefaultAxis ¶
Default axis used when no axis is specified for a LabeledArray.
It behaves mostly as an array [Nullable(1), Nullable(2), ...].
However, one notable exception is when using @select/selct/extract/discard/getindex/etc to choose, set or drop specific elements of a LabeledArray.
In this case, the result array of reduced size will again have a DefaultAxis of an appropriate size.