Skip to content

Commit fb7e34a

Browse files
committed
Merge branch 'better_set2' into better_set
2 parents 8ba22e4 + 626407c commit fb7e34a

35 files changed

Lines changed: 1228 additions & 592 deletions

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DimensionalData"
22
uuid = "0703355e-b756-11e9-17c0-8b28908087d0"
33
authors = ["Rafael Schouten <rafaelschouten@gmail.com>"]
4-
version = "0.29.12"
4+
version = "0.29.13"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

docs/src/api/reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ For transforming DimensionalData objects:
6969

7070
```@docs
7171
groupby
72+
combine
7273
DimensionalData.DimGroupByArray
7374
Bins
7475
ranges

src/DimensionalData.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ using .Dimensions: StandardIndices, DimOrDimType, DimTuple, DimTupleOrEmpty, Dim
4141
import .Dimensions: dims, refdims, name, lookup, kw2dims, hasdim, label, checkaxes, _astuple
4242

4343
import .Lookups: Safety, Safe, Unsafe, SelectorOrInterval, Begin, End
44-
import .Lookups: metadata, reorder, set, _set, rebuild, basetypeof,
44+
import .Lookups: metadata, reorder, set, unsafe_set, _set, rebuild, basetypeof,
4545
order, span, sampling, locus, val, index, bounds, intervalbounds,
4646
hasselection, units
4747

@@ -87,7 +87,7 @@ export dimnum, hasdim, hasselection, otherdims
8787
export set, rebuild, reorder, modify, broadcast_dims, broadcast_dims!,
8888
mergedims, unmergedims, maplayers
8989

90-
export groupby, seasons, months, hours, intervals, ranges
90+
export groupby, combine, seasons, months, hours, intervals, ranges
9191

9292

9393
export @d
@@ -120,6 +120,7 @@ include("tables.jl")
120120
include("plotrecipes.jl")
121121
include("utils.jl")
122122
include("set.jl")
123+
include("opaque.jl")
123124
include("groupby.jl")
124125
include("precompile.jl")
125126
include("interface_tests.jl")

src/Dimensions/dimension.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ Base.axes(d::Dimension, i) = axes(d)[i]
277277
Base.eachindex(d::Dimension) = eachindex(val(d))
278278
Base.length(d::Dimension) = length(val(d))
279279
Base.ndims(d::Dimension) = 0
280+
Base.parentindices(d::Dimension{<:AbstractArray}) = parentindices(parent(d))
280281
Base.ndims(d::Dimension{<:AbstractArray}) = ndims(val(d))
281282
Base.iterate(d::Dimension{<:AbstractArray}, args...) = iterate(lookup(d), args...)
282283
Base.first(d::Dimension) = val(d)

src/Dimensions/primitives.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,20 +211,25 @@ julia> dimnum(A, Y)
211211
```
212212
"""
213213
function dimnum end
214-
@inline function dimnum(x, q1, query...)
215-
all(hasdim(x, q1, query...)) || _extradimserror(otherdims(x, (q1, query...)))
216-
_dim_query(_dimnum, MaybeFirst(), x, q1, query...)
214+
@inline function dimnum(x, query::Tuple)
215+
all(hasdim(x, query)) || _extradimserror(otherdims(x, query))
216+
_dim_query(_dimnum, MaybeFirst(), x, query...)
217217
end
218+
@inline dimnum(x, q1::Union{DimOrDimType,Integer}, query::Union{DimOrDimType,Integer}...) =
219+
dimnum(x, (q1, query...))
218220
@inline dimnum(x, query::Function) =
219221
_dim_query(_dimnum, MaybeFirst(), x, query)
222+
@inline dimnum(x, q1, query...) =
223+
throw(ArgumentError("`dimnum` accepts Dimensions, Symbols, Integers or any of these in a Tuple, or a predicate, function. not $((q1, query...))."))
220224

221-
@inline _dimnum(f::Function, ds::Tuple, query::Tuple{Vararg{Int}}) = query
225+
@inline _dimnum(f::Function, ds::Tuple, query::Tuple{Vararg{Integer}}) = query
222226
@inline function _dimnum(f::Function, ds::Tuple, query::Tuple)
223227
numbered = map(ds, ntuple(identity, length(ds))) do d, i
224228
rebuild(d, i)
225229
end
226230
map(val, _dims(f, numbered, query))
227231
end
232+
_dimnum(f::Function, ds::Tuple) = ()
228233

229234
"""
230235
hasdim([f], x, query::Tuple) => NTuple{Bool}

src/Dimensions/set.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ unsafe_set(dims::DimTuple, a1::Union{Dimension,Pair}, a2::Union{Dimension,Pair},
1313
_set(Unsafe(), dims, a1, a2, args...)
1414

1515
_set(s::Safety, dims::DimTuple, l::LookupSetters) =
16-
_set(s, dims, map(d -> basedims(d) => l, dims)...)
16+
_set(s, dims, map(d -> rebuild(d, l), dims)...)
1717

1818
# Convert pairs to wrapped dims and set
1919
_set(s::Safety, dims::DimTuple, p::Pair, ps::Pair...) =
@@ -40,9 +40,10 @@ end
4040
# Set things wrapped in dims
4141
_set(s::Safety, dim::Dimension, wrapper::Dimension{<:DimSetters}) = begin
4242
rewrapped = _set(s, dim, basetypeof(wrapper))
43-
x = _set(s, rewrapped, val(wrapper))
44-
x
43+
_set(s, rewrapped, val(wrapper))
4544
end
45+
_set(s::Safety, dim::Dimension, l::Union{Lookup,LookupSetters}) =
46+
rebuild(dim, _set(s, val(dim), l))
4647
# Set the dim, checking the lookup
4748
_set(s::Safety, dim::Dimension, newdim::Dimension) =
4849
_set(s, newdim, _set(s, val(dim), val(newdim)))
@@ -61,6 +62,9 @@ _set(::Safety, ::Nothing, x::Dimension) = x
6162
_set(::Safety, ::Nothing, ::Nothing) = nothing
6263
_set(::Safety, x, ::Nothing) = x
6364
_set(::Safety, ::Nothing, x) = x
65+
# For ambiguity
66+
_set(::Safety, dims::DimTuple, ::Nothing) = dims
67+
_set(::Safety, dims::Lookup, ::Nothing) = dims
6468

6569
@noinline _wrongdimserr(dims, w) =
6670
throw(ArgumentError("dim $(basetypeof(w))) not in $(map(basetypeof, dims))"))

src/Lookups/Lookups.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,15 @@ export Unaligned, Transformed, ArrayLookup
5959
# Deprecated
6060
export LookupArray
6161

62-
const StandardIndices = Union{AbstractArray{<:Integer},Colon,Integer,CartesianIndex,CartesianIndices}
63-
6462
# As much as possible keyword rebuild is automatic
6563
rebuild(x; kw...) = ConstructionBase.setproperties(x, (; kw...))
6664

67-
include("metadata.jl")
6865
include("lookup_traits.jl")
66+
include("metadata.jl")
6967
include("lookup_arrays.jl")
68+
include("beginend.jl")
7069
include("predicates.jl")
7170
include("selector.jl")
72-
include("beginend.jl")
7371
include("indexing.jl")
7472
include("methods.jl")
7573
include("utils.jl")

src/Lookups/beginend.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Base.to_indices(A, inds, (r, args...)::Tuple{<:Union{Begin,End,<:LazyMath},Varar
4545
_to_index(inds, a::Int) = a
4646
_to_index(inds, ::Begin) = first(inds)
4747
_to_index(inds, ::End) = last(inds)
48+
_to_index(inds, ::Type{Begin}) = first(inds)
49+
_to_index(inds, ::Type{End}) = last(inds)
4850
_to_index(inds, l::LazyMath{End}) = l.f(last(inds))
4951
_to_index(inds, l::LazyMath{Begin}) = l.f(first(inds))
5052

src/Lookups/lookup_arrays.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Base.first(l::Lookup) = first(parent(l))
3232
Base.last(l::Lookup) = last(parent(l))
3333
Base.firstindex(l::Lookup) = firstindex(parent(l))
3434
Base.lastindex(l::Lookup) = lastindex(parent(l))
35+
Base.parentindices(l::Lookup) = parentindices(parent(l))
3536
function Base.:(==)(l1::Lookup, l2::Lookup)
3637
basetypeof(l1) == basetypeof(l2) && parent(l1) == parent(l2)
3738
end
@@ -159,11 +160,10 @@ NoLookup() = NoLookup(AutoValues())
159160
rebuild(l::NoLookup; data=parent(l), kw...) = NoLookup(data)
160161

161162
# Used in @d broadcasts
162-
struct Length1NoLookup <: AbstractNoLookup end
163-
Length1NoLookup(::AbstractVector) = Length1NoLookup()
164-
165-
rebuild(l::Length1NoLookup; kw...) = Length1NoLookup()
166-
Base.parent(::Length1NoLookup) = Base.OneTo(1)
163+
struct Length1NoLookup{A<:AbstractUnitRange} <: AbstractNoLookup
164+
data::A
165+
end
166+
Length1NoLookup() = Length1NoLookup(Base.OneTo(1))
167167

168168
"""
169169
AbstractSampled <: Aligned
@@ -468,7 +468,7 @@ abstract type AbstractCategorical{T,O} <: Aligned{T,O} end
468468
order(lookup::AbstractCategorical) = lookup.order
469469
metadata(lookup::AbstractCategorical) = lookup.metadata
470470

471-
const CategoricalEltypes = Union{AbstractChar,Symbol,AbstractString}
471+
const CategoricalEltypes = Union{AbstractChar,Symbol,AbstractString,DataType}
472472

473473
function Adapt.adapt_structure(to, l::AbstractCategorical)
474474
rebuild(l; data=Adapt.adapt(to, parent(l)), metadata=NoMetadata())
@@ -866,6 +866,7 @@ promote_first(x1, x2, xs...) =
866866
# Fallback NoLookup if not identical type
867867
promote_first(l1::Lookup) = l1
868868
promote_first(l1::L, ls::L...) where L<:Lookup = rebuild(l1; metadata=NoMetadata)
869+
promote_first(l1::L, ls::L...) where L<:AbstractNoLookup = l1
869870
function promote_first(l1::Lookup, ls1::Lookup...)
870871
ls = _remove(Length1NoLookup, l1, ls1...)
871872
if length(ls) != length(ls1) + 1

src/Lookups/selector.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
const StandardIndices = Union{
2+
AbstractArray{<:Integer},
3+
Colon,
4+
Integer,
5+
CartesianIndex,
6+
CartesianIndices,
7+
BeginEndRange,
8+
}
9+
110
struct SelectorError{L,S} <: Exception
211
lookup::L
312
selector::S

0 commit comments

Comments
 (0)